3 ms·
JavaScript doesn't make the same distinctions between numerically indexed arrays, string-indexed associative arrays and objects that you would see in most other
by Silhouette 17y ago
JavaScript doesn't make the same distinctions between numerically indexed arrays, string-indexed associative arrays and objects that you would see in most other languages. This explains a lot of the perceived oddities of JavaScript to programmers coming from backgrounds working with other programming languages, e.g., why calling sort() on an array of numbers doesn't do what you might expect and why the for-each loop in JavaScript iterates over indices rather than values.
- silentbicycle 17y agoThe same is true of Lua, except it recognizes when you have consecutive integer keys and implements it as an actual array.