标签:ret pre console return ons ... 排序 cti name
var arr2=[{name:‘阿拉蕾‘,age:9},
{name:‘考拉‘,age:6},
{name:‘靓仔‘,age:10}];
arr2.sort(function (c,d) {//按照age由小到大进行排序
return c.age>d.age?1:-1;//c-d<0升序排序,c-d>0降序排序
});
console.log(arr2);//==============>[{name:‘考拉‘,age:6},{name:‘阿拉蕾‘,age:9},{name:‘靓仔‘,age:10}];
标签:ret pre console return ons ... 排序 cti name
原文地址:http://www.cnblogs.com/luxiaoxiao/p/6036402.html