JS数组对象排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var commonData = [{
"name":"xxx",
"count":1
},{
"name":"xxx",
"count":5
},{
"name":"xxx",
"count":2
},{
"name":"xxx",
"count":3
}]

commonData.sort(function (obj1, obj2) {
let minCount = obj1["count"];
let maxCount = obj2["count"];
return maxCount - minCount;
})