对象数组降序或者升序

2019-12-08  本文已影响0人  Mark_ZSQ
let arr = [
    {name: '西安市1', value: '100%'},
    {name: '西安市2', value: '99%'},
    {name: '西安市3', value: '100%'},
    {name: '威阳市2', value: '88.2%'},
    {name: '榆林市2', value: '66.6%'},
    {name: '榆林市1', value: '34.2%'},
    {name: '延安市4', value: '80%'},
    {name: '南洛市2', value: '90%'},
    {name: '榆林市9', value: '81.3%'},
    {name: '榆林市0', value: '34.2%'}
];


arr.sort((a, b) => {
    return parseInt(b.value) - parseInt(a.value)
});

arr.sort((a, b) => {
    return parseInt(a.value) - parseInt(b.value)
});
上一篇下一篇

猜你喜欢

热点阅读