es6 进行数组,数组对象 排序,降序升序
升序
let data = [
{value: 335, name: '家电'},
{value: 310, name: '服装'},
{value: 274, name: '食品'},
{value: 235, name: '数码'},
{value: 400, name: '家纺'}
]
data.sort(function (a, b) {return a.value – b.value;})
降序
let data = [
{value: 335, name: '家电'},
{value: 310, name: '服装'},
{value: 274, name: '食品'},
{value: 235, name: '数码'},
{value: 400, name: '家纺'}
]
data.sort(function (a, b) {return b.value – a.value;})