4 ms·
I’m pretty sure this is wrong. JS objects and arrays are different. The former will only yield elements from the array itself when iterated on, and has a consis
by roblabla 7y ago
I’m pretty sure this is wrong. JS objects and arrays are different. The former will only yield elements from the array itself when iterated on, and has a consistent iteration order, while the later does not.
- mncharity 7y agohttps://www.ecma-international.org/ecma-262/#sec-array-exotic-objects https://www.ecma-international.org/ecma-262/#sec-array-exoti...
- TurningCanadian 7y agoOrder is consistent in both https://www.stefanjudis.com/today-i-learned/property-order-is-predictable-in-javascript-objects-since-es2015/ https://www.stefanjudis.com/today-i-learned/property-order-i...
- cutler 7y agoJS arrays are array-like objects. That's the official line anyway.
- azernik 7y agoThat's because arrays happen to override the special [Symbol.iterator] method: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/@@iterator https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... Arrays are objects of class Array which have special literals, override the toString() method, and update the non-enumerable "length" property on certain operations. Try calling Object.keys([1, 2, 3]), or even better try Object.getOwnPropertyNames([1, 2, 3])