5 ms·
This is a gotcha in Lua, too, but there it makes a bit more sense - tables ("dicts", if you prefer) explicitly have a key/value part and an array part - if you
by silentbicycle 16y ago
This is a gotcha in Lua, too, but there it makes a bit more sense - tables ("dicts", if you prefer) explicitly have a key/value part and an array part - if you have a table with keys 1* to N, it's handled internally as an array (with O(1) lookups), but #, the length operator, explicitly gives you the upper bound for the array portion. In practice, this isn't a big deal, since the very different performance etc. means that they're usually used in very different ways.
It sounds like Javascript has the same downside, but without any upside.
* Yeah, Lua is 1-indexed. Nothing's perfect. Lisp has all those parens, Python has the whitespace thing...you get over it. :)