Accessing (n)th key from an object

Jordan Harband ljharb at
Tue Apr 24 18:07:53 UTC 2018

Regardless of what's in the spec, relying on objects having an order among
their properties violates the conceptual mental model of objects: a bag of
unordered key/value pairs.

If you want to convert an array - the best way to preserve order - into an
object for "performance" reasons, then you may also want to preserve an
array of IDs so that ordering can be relied upon.

On Tue, Apr 24, 2018 at 10:26 AM, T.J. Crowder <
tj.crowder at> wrote:

> On Tue, Apr 24, 2018 at 5:58 PM, Augusto Moura <augusto.borgesm at>
> wrote:
> > Assuming `Object.keys` has the same order as a simple `` (as
> stated
> > in
> > mdn)[
> JavaScript/Reference/Global_Objects/Object/keys]...
> 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
> loop):
> > 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):
> ```js
> 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
> [1]:
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list