数组根据对象的属性重新排序
const list = [
{id:1,age:44,index: 3},
{id:2,age:32,index: 1},
{id:3,age:22,index: 4},
{id:4,age:26,index: 2},
]
const compare = key => {
return (value1, value2) => {
const index1 = value1[key]
const index2 = value2[key]
return index1 - index2
}
}
const list2 = list.sort(compare('age'))
const list3 = list.sort(compare('index'))
A little hug, little gift.
All of little something.
these are our meories.