假設我有一個初始化迭代爲了在Javascript for..in循環的
var letters = {q:0, t:0, o:0, b:0, y:0, n:0, u:0, m:0, p:0,
w:0, a:0, d:0, k:0, v:0, c:0, z:0, l:0, j:0,
i:0, e:0, g:0, s:0, x:0, r:0, h:0, f:0};
,然後我要遍歷這個密鑰的Javascript對象對象
for(var letter in letters) {
// code goes here
}
在這兩個Firefox 3和Internet Explorer 8中,對象按其在對象聲明(q,t,o,b,y等)中列出的順序進行迭代。
我可以依靠這個嗎?假設我在迭代之前不以任何方式修改我的對象。它是ECMAScript標準的一部分嗎?有誰知道哪些瀏覽器按聲明的順序迭代?
Dup:http://stackoverflow.com/questions/919027/are-object-variables-in-javascript-enumerated-in-the-order-they-were-added and http://stackoverflow.com/questions/280713/elements-order-for-in-loop-in-javascript – 2009-06-10 15:17:57