iteration order for Object

Brendan Eich brendan at
Sat Mar 12 10:41:27 PST 2011

On Mar 12, 2011, at 9:54 AM, David Bruant wrote:

> The little "issue" I see in returning 1) index properties in ascending
> order 2) all other properties in addition order is that there is a bit
> of information lost in the process: overall property addition order
> (index properties included).

This is an issue in theory. Beware _a priori_ reasoning about usability issues.

In practice both users and (especially) implementors Do Not Want indexed properties enumerated in insertion order. The proof is the use of for-in over arrays, still common enough, also advised against (but that is like talking back to the tide).

> What is the rational or use case behind having index properties at first
> for objects and then the rest of properties?

The "rationale" (such as it is) is that JS conflates lists and dicts in objects, but users mostly think about one or the other. When combining indexed and named properties, many users still want for-in to work sensibly and that means the list properties first in index order, the dict properties after in insertion order.


More information about the es-discuss mailing list