let arr=[
{
name:"张三",
score:2,
age:1
},{
name:"张四",
score:1,
age:3
},{
name:"张五",
score:2,
age:2
},{
name:"张六",
score:1,
age:1
},
];
arr.sort((a,b)=>{
if(a.score!=b.score){
return b.score-a.score
}else{
return b.age-a.age
}
})
结果:
[
{
name:"张五",
score:2,
age:2
},{
name:"张三",
score:2,
age:1
},{
name:"张四",
score:1,
age:3
},{
name:"张六",
score:1,
age:1
},
]