arraySort(field) {
return (a, b) => {
const a = a[field]
const b = b[field]
return a - b
}
}
const arrayObject = [
{
id: 1,
name: "aa"
},
{
id: 2,
name: "aa"
},
{
id: 3,
name: "aa"
},
]
// 调用
console.log(arrayObject.sort(this.arraySort('id')), '=========')
Es6 Object类型数组排序
最新推荐文章于 2024-04-12 07:26:37 发布