var list = [
{
name:"张三",
age:23
},{
name:"李四",
age:21
},{
name:"王五",
age:25
},
];
const sortParse = (c)=> {//排序
return (a,b)=> { return a[c] - b[c] }
}
list.sort(sortParse('age'));
或简写:
list.sort((a,b)=> { return a['age'] - b['age'] });