Yup, {} is an empty object, and [] is an empty array. Note that an array is a kind of object optimized for handling a list of values, but, like any Javascript object, it can take other attributes, such as "one" or "two" - this is how it can support methods like myArray.push(1) : push is an attribute of all arrays. In fact, you can even say myArray["push"] = someOtherFunction to myArray["push"] = someOtherFunction push without problems. Arrays, like all Javascript objects, support arbitrary key assignments.
Ultimately, however, this is due to off-screen performance. If you want to keep a consistent list of values, the array will handle it much better and offer some useful attributes like push , shift , length , etc. - plus, future developers will really find out what you are doing. If you just want to store key-value pairs, an object is the way to go because it is not bogged down at this extra weight.
In short, although they both support key-value pairs, they are completely different behind the scenes. Don't worry too much about it and use what works best for you.
source share