loading...

re: JS: Arrays || Artificial Arrays, which are better? VIEW POST

FULL DISCUSSION
 

So arrays are implemented differently to objects in V8 for instance, iterating arrays is clearly much faster than iterating objects. If you have numeric indices then an array makes a lot of sense. If you want to work over the majority of the contents of the collection, then arrays also make more sense.

If you want to look something up with a string value then objects are very fast - much faster than searching an array for the item. An array index lookup should be faster than an object lookup because the process to get a value from an object is to convert the key into a hash, in the case of an array the number is a direct reference into the collection of members.

If you want to use a key that is not a string then use a Map.

 
code of conduct - report abuse