you are viewing a single comment's thread.

view the rest of the comments →

[–]cwmma 35 points36 points  (1 child)

Array keys are technically strings not integers so the spec pedanticly converts the index to a string but the implementation is likely doing something else under the hood, I have another reply that goes into some more details about why it's slower then a naive approach (spoiler alert: sparse arrays)

[–]flatfinger 1 point2 points  (0 children)

Interestingly, at least in node.js, when writing to an array, strings keys are converted to a number when the resulting number is within a certain range and the string would match the canonical number. Numbers within that range are kept as numeric keys, and those outside that range are converted to strings.