Objects are not built on arrays. Objects have their own optimizations.
In general:
- Objects are for "structs", structures of predictable "shape" and keys known in advance (even though they can be used with dynamic keys, you should use Maps for that. See below).
- Arrays are for lists (and queues, and stacks), structures where the keys are numbers, or where the order of elements matters. Arrays are "special" objects, not the other way around. (You can put string-based properties on an array, just like any object. Please don't do that though).
- Maps are for hash tables/dictionaries, structures where the keys are dynamic and not known in advance.
typeof []; //returns objector thisnew String()I would rather say everything in JS is build on objects.myArr = ['this', 'is', 'an', 'array']is actually{ 0: 'this', 1: 'is', 2: 'an', 3: 'array' }behind the scenes.