Accessing (n)th key from an object

T.J. Crowder tj.crowder at
Tue Apr 24 18:22:03 UTC 2018

On Tue, Apr 24, 2018 at 7:07 PM, Jordan Harband <ljharb at> wrote:
> 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.

Absolutely agree. As I said originally, relying on the order of the
properties in the object is almost always a bad idea.

@somonek, an object with an array of keys is probably your best
solution. Wrap it up in an object with an API that all of the code
updating it can use, so you don't have consistency issues. You could
even give it an iterator. :-)

-- T.J. Crowder

More information about the es-discuss mailing list