compare(property){
return function(a,b){
var value1 = a[property];
var value2 = b[property];
return value1 - value2;
}
}
var arr = [
{name:'zopp',age:0},
{name:'gpp',age:18},
{name:'yjj',age:8}
];
console.log(arr.sort(compare('age')))
对数组中对象的属性进行排序
最新推荐文章于 2024-02-03 18:54:36 发布