3 ms·
Not just the length property, but also a special array API (push, pop, etc). So there is no equivalence between an array and the simple object constructed from
by cema 13y ago
Not just the length property, but also a special array API (push, pop, etc). So there is no equivalence between an array and the simple object constructed from its keys and values, but the object would correctly represent a snapshot of the subset of array key-value pairs.
- jdlshore 13y agoTechnically, the special API is because arrays extend Array.prototype. You could create an object that does the same, and push(), pop(), etc would work.* Try going to http://www.objectplayground.com http://www.objectplayground.com and putting in the following code, selecting the "Show built-in objects" option, and evaluating: this.array = []; this.object = Object.create(Array.prototype); this.object.push("foo"); this.object.push("bar"); *Well, they sort of work. They use and modify the "length" property, so you could see some weird behavior under some circumstances. Not recommended for production use. :-)
- cema 13y agoYes, but a literal will still be either an array or an object, so that var arr = ['a','b'] will be different from var obj = {0:'a',1:'b'}