Accessing (n)th key from an object

T.J. Crowder tj.crowder at
Tue Apr 24 17:26:20 UTC 2018

On Tue, Apr 24, 2018 at 5:58 PM, Augusto Moura <augusto.borgesm at>
> Assuming `Object.keys` has the same order as a simple `` (as stated
> in
> mdn)[].

We'll have to fix that page, the spec does not define the order in which
`for-in` will enumerate property names. (It does define the order in which
`Object.keys` will provide the property names, now, but not `for-in`.) That
said, all modern and modern-ish implementations I've tested (to be fair,
just V8, SpiderMonkey, Chakra, and IE11's JScript) do indeed follow the
defined order with `for-in` as well, with an object's own properties coming
before inherited ones - (IE11-friendly
version without Symbols: (Provided I
haven't screwed up that test.) But it's specifically *not* specified - from
[EnumerateObjectProperties][1] (the op `for-in` uses to initialize its

> The mechanics **and order** of enumerating the properties **is not
specified** but must conform to the rules specified below.

*(my emphasis)* It says it has to use [[OwnPropertyKeys]] to get the own
property keys at each level, but doesn't -- as far as I can tell -- define
the sequence of own vs. inherited properties.

`Object.entries` follows the order (own properties only):

const [first, second,] = Object.entries(obj);

...but I don't think that, or `keysIterator`, really helps somonek vs. what
he's doing now (`Object.keys`).

-- T.J. Crowder

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list