iteration order for Object

Kyle Simpson getify at
Mon Mar 14 09:16:10 PDT 2011

> Aside from the JSON example of populating a dropdown list given (which I 
> will agree is a real if contrived use case), there has been a lot of talk 
> of "thousands of web developers" depending on preserving insertion order, 
> but not one concrete example -- do you have one?

Two examples I've seen recently in projects, both relying primarily on the 
for-in iteration order of an object:

1. exporting objects (like JSON, etc) to log files (server-side 
javascript)... needing a reliable order for the keys to be printed to the 
log file output, like the "datetime" field first, etc. A variation on this 
is using JSON.stringify(obj) and wanting the JSON output to have a reliable 
output order, also for log files.

2. Using an object literal as a UI/form "configuration" where a each field 
of the object represents a form element in a form-builder UI. If the 
iteration order of the object is different in different engines/browsers, 
the UI ends up being displayed in different orders.


More information about the es-discuss mailing list