js获取数组对象中,所有的最大值数据
2023-06-08 本文已影响0人
甘道夫老矣
let arr = [
{ name: 'Alice', age: 25,code:100, },
{ name: 'Bob', age: 30 ,code:200},
{ name: 'Charlie', age: 35,code:300 },
{ name: 'David', age: 35,code:400 }
];
result.sort((a: any, b: any) => {
if (+a.age=== +b.age) {
return +a.code> +b.code? 1 : -1;
} else {
return +a.age> +b.age? -1 : 1
}
})
console.log(maxAges); // [{ name: 'Charlie', age: 35 }, { name: 'David', age: 35 }]