js从一个 对象数组 中根据属性值大小排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
let arr = [
{name:'a',age:23},
{name:'b',age:33},
{name:'c',age:9},
{name:'d',age:17},
{name:'e',age:25},
{name:'f',age:18},
]

console.log(arr);

let arr2 = arr.sort(function(a,b){
return a.age-b.age
})
console.log(arr2);