iteration order for Object

John Tamplin jat at
Thu Mar 10 18:50:01 PST 2011

On Thu, Mar 10, 2011 at 9:00 PM, Charles Kendrick <charles at>wrote:

> People use Objects as classes, instances, "associative arrays" / Maps, etc.
>  Numeric keys are a tiny minority and there would be no measurable
> performance gains for special treatment of such keys *on Object*.

An associative array is typically a hash map or perhaps a tree map.  A
typical implementation will either iterate through such values in either an
undetermined order or in order by the keys -- preserving the insertion order
would be more expensive and preclude most options for implementation.

If you care about order, you don't use a hash map, and a JS object literal
seems more closely related to a hash map than anything else.

An alternative you didn't consider in your original post is using a single
array, which is guaranteed to not change the order and never pick up
additional properties:

     "storedValue1", "displayValue1",
     "storedValue2", "displayValue2",
     "storedValue3", "displayValue3"

John A. Tamplin
Software Engineer (GWT), Google
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list