首页 > 代码库 > 数组的排序..........加深难度

数组的排序..........加深难度

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}];

数组的排序..........加深难度