Object无序

之前看书,听Nicholas说过,Object不能保证顺序,今天通过一个BUG认识到了

问题:

var a = {3:'a', 1:'b', 2:'c'};
console.log(a);

在Chrome下出来的Object是按数值Key排序的,而其他浏览器是原始顺序

{1:'b', 2:'c', 3:'a'} //chrome
{3:'a', 1:'b', 2:'c'} //others

 

解决:

根据业务需要使用 string或者array

 

 

posted @ 2011-12-13 14:38  王冶soda  阅读(188)  评论(0编辑  收藏  举报