Accessing (n)th key from an object
tj.crowder at farsightsoftware.com
Tue Apr 24 17:26:20 UTC 2018
On Tue, Apr 24, 2018 at 5:58 PM, Augusto Moura <augusto.borgesm at gmail.com>
> Assuming `Object.keys` has the same order as a simple `for..in` (as stated
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 - http://jsfiddle.net/arhbn3k2/1/ (IE11-friendly
version without Symbols: http://jsfiddle.net/arhbn3k2/5/). (Provided I
haven't screwed up that test.) But it's specifically *not* specified - from
[EnumerateObjectProperties] (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, ...rest] = 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...
More information about the es-discuss