Iterating JavaScript object properties and arrays with for..in when ordering is important

前端 未结 3 552
醉梦人生
醉梦人生 2021-01-14 07:18

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

3条回答
  •  醉话见心
    2021-01-14 07:39

    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.

提交回复
热议问题