关键:23价值AAOutput in Opera and Chrome (Wrong)Key: 12 Value BBKey: 23 Value AA我试图制作一个这样的逆序对象I attempted to make an inverse ordered object like thisvar obj1={"AA":23,"BB":12};for(i in obj1) document.write("Key: "+obj[i] +" "+"Value: "+i);然而输出是相同的。是否有办法通过较小的更改获得所有浏览器相同的行为?However the output is the same. Is there a way to get for all browser the same behaviour with small changes?推荐答案否。 JavaScript对象属性没有固有的顺序。总算很幸运,在循环运行时,的顺序是什么。No. JavaScript Object properties have no inherent order. It is total luck what order a for...in loop operates.如果你想订购,你会必须改为使用数组:If you want order you'll have to use an array instead:var map= [[23, 'AA'], [12, 'BB']];for (var i= 0; i<map.length; i++) document.write('Key '+map[i][0]+', value: '+map[i][1]); 这篇关于如何按照编写的顺序迭代javascript对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 10:54