Elements order in a “for (… in …)” loop

后端 未结 9 667
终归单人心
终归单人心 2020-11-21 07:27

Does the \"for…in\" loop in Javascript loop through the hashtables/elements in the order they are declared? Is there a browser which doesn\'t do it in order?
The object

9条回答
  •  你的背包
    2020-11-21 08:17

    The elements of an object that for/in enumerates are the properties that don't have the DontEnum flag set. The ECMAScript, aka Javascript, standard explicitly says that "An Object is an unordered collection of properties" (see http://www.mozilla.org/js/language/E262-3.pdf section 8.6).

    It's not going to be standards conformant (i.e. safe) to assume all Javascript implementations will enumerate in declaration order.

提交回复
热议问题