This has been an age old question and I am aware of the usual reasons for not using for..in
or perhaps even objects when any sort of ordering is needed, but I r
Tests on IE 5.5-6-7-8 showed the exact same behavior. The properties are ordered. The deleted property keeps its position.
But as it is non-standard behavior it can break with IE9, or any browser's next version...
And maybe I've missed something but what's the point? Saving some characters in comparison to a more robust code, that runs well with 3rd party ads, tracking systems, widgets etc.?
Let alone supporting mobile browsers, and the desktop ones with tiny market share.
Running your test on IE8 on WinXP pro SP2 confirms the MDC article. IE8 iterates the members in the order they are declared; if an existing property is deleted and then later reassigned then its original iteration position is maintained. Other browsers (I verified Chrome 5 and Firefox 3) place the reassigned property at the end of the iteration order.
There are more browsers than just those mentioned here: there are other current browsers and future browsers. None of them are obliged to implement any ordering when iterating over the properties of an object, and will not be for a long time, since the recent ECMAScript 5 specifies no ordering. Indeed, the Chrome development team is refusing to change its implementation despite vocal requests to make it conform with other browsers.
Any assumptions based on observed behaviour of a handful of current browsers is shaky at best; as observed, not all current browsers behave the same and future browsers may choose not to conform to your assumptions and have every right to do so. Therefore I strongly recommend not relying on any particular ordering in any of your code.