关于javascript:es6-进行数组数组对象-排序降序升序

49次阅读

共计 357 个字符,预计需要花费 1 分钟才能阅读完成。

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;})

正文完
 0