Do Undefined Values In Javascript Arrays Use Any Memory Or Get Iterated Over In A For-in Loop?
I'm building an Entity System for a game, and basically I'm not sure whether I should use simple objects (dictionaries) or arrays to to store the entities/components by their id. M
Solution 1:
Arrays are not just objects. In particular the length
property is very magic.
Of course, a JavaScript engine is allowed to represent the array internally in any way it chooses, as long as the external API remains the same. For instance, if you set randomly separated values then they may be stored as a hash, but if you set consecutive values then they may be optimised into an array.
for ... in
does not enumerate properties that are not set. This includes an array literal that skips values e.g. [true, , false]
, which will only enumerate indices 0 and 2.
Post a Comment for "Do Undefined Values In Javascript Arrays Use Any Memory Or Get Iterated Over In A For-in Loop?"