3 ms·
Eich states that in the original implementation of JS, Array was just Object with a length property. How did it handle order?
by eliotfowler 12y ago
Eich states that in the original implementation of JS, Array was just Object with a length property. How did it handle order?
- serve_yay 12y agoIn JS, arrays are just objects where the indices are keys. There is a small bit of magic where any time you alter an array object, the length is changed to the largest numeric key the object has, plus 1.
- willvarfar 12y agoobject[0] is object["0"]
- TazeTSchnitzel 12y agoThe order is just the number in the key. So the "0" item is the first, "1" is the second, etc. As it's just an object you can stick non-sequential-positive-integer keys on it, but that rather defeats the purpose.