“for (... in ...)”循环中的元素顺序 - Elements order in a "for (… in …)" loop

10/14 10:55
阅读数 0

问题:

Does the "for…in" loop in Javascript loop through the hashtables/elements in the order they are declared? Javascript 中的“for...in”循环是否按照声明的顺序遍历哈希表/元素? Is there a browser which doesn't do it in order?是否有浏览器不按顺序执行?
The object I wish to use will be declared once and will never be modified.我希望使用的对象将被声明一次并且永远不会被修改。

Suppose I have:假设我有:

var myObject = { A: "Hello", B: "World" };

And I further use them in:我进一步将它们用于:

for (var item in myObject) alert(item + " : " + myObject[item]);

Can I expect 'A : "Hello"' to always come before 'B : "World"' in most decent browsers?在大多数体面的浏览器中,我可以期望 'A : "Hello"' 总是出现在 'B : "World"' 之前吗?


解决方案:

参考一: https://en.stackoom.com/question/1B1d
参考二: https://stackoom.com/question/1B1d
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部