Closed nathan closed 7 years ago
object iteration order is de facto guaranteed
Is it really? I thought that was implementation-defined.
If not, that would indeed be much nicer. :-)
implementation-defined
Technically, yesâthe spec doesn't define an iteration order for for-in loops. Realistically, all engines iterate Object keys in creation order, as long as they are not 32-bit-integer-like (which V8 handles specially)âsee the rather extensive discussion here.
EDIT: Actually, for ordinary objects [[OwnPropertyKeys]] returns non-integer own property String keys in creation order. So when you call Reflect.ownKeys
or Object.getOwnPropertyNames
(but not Object.keys
) you get the correct order. for-in loops are terrible anyway.
It seems easier to write this:
than this:
(object iteration order is de facto guaranteed for non-integer keys)