I have such an array object that I need to sort.

drawerList:[
        {url:"../../static/images/icon/coin-etc.png",name:"ETC",zhangfu:+122.33,price:228.253,about:3.3248,state:1},
        {url:"../../static/images/icon/coin-bat.png",name:"BAT",zhangfu:-12.20,price:68.53,about:3.3248,state:0},
        {url:"../../static/images/icon/coin-gram.png",name:"GRA",zhangfu:+121.13,price:68.3223022,about:3.3248,state:1},
        {url:"../../static/images/icon/coin-eth.png",name:"ETH",zhangfu:+12.83,price:68.25232,about:3.3248,state:1},
        {url:"../../static/images/icon/coin-bat.png",name:"BAT",zhangfu:-122.03,price:12.25322232,about:3.3248,state:0},
        {url:"../../static/images/icon/coin-etc.png",name:"ETC",zhangfu:-12.13,price:68.253232,about:3.3248,state:0},
        {url:"../../static/images/icon/coin-bat.png",name:"BAT",zhangfu:-9.03,price:68.253232,about:3.3248,state:0},
      ],

I want to sort the array according to the zhangfu field in the click event respectively

excuse me, how should I write this js method? I"ve tried several ways of writing, but they don"t seem to be quite right.


let obj = {
    drawerList:[
        {url:'../../static/images/icon/coin-etc.png',name:'ETC',zhangfu:+122.33,price:228.253,about:3.3248,state:1},
        {url:'../../static/images/icon/coin-bat.png',name:'BAT',zhangfu:-12.20,price:68.53,about:3.3248,state:0},
        {url:'../../static/images/icon/coin-gram.png',name:'GRA',zhangfu:+121.13,price:68.3223022,about:3.3248,state:1},
        {url:'../../static/images/icon/coin-eth.png',name:'ETH',zhangfu:+12.83,price:68.25232,about:3.3248,state:1},
        {url:'../../static/images/icon/coin-bat.png',name:'BAT',zhangfu:-122.03,price:12.25322232,about:3.3248,state:0},
        {url:'../../static/images/icon/coin-etc.png',name:'ETC',zhangfu:-12.13,price:68.253232,about:3.3248,state:0},
        {url:'../../static/images/icon/coin-bat.png',name:'BAT',zhangfu:-9.03,price:68.253232,about:3.3248,state:0},
      ]
}

//
let arr = obj.drawerList.concat();
//
arr.sort(function(i,j){
    return i.zhangfu - j.zhangfu
})

let data = [
    {url:'../../static/images/icon/coin-etc.png',name:'ETC',zhangfu:+122.33,price:228.253,about:3.3248,state:1},
    {url:'../../static/images/icon/coin-bat.png',name:'BAT',zhangfu:-12.20,price:68.53,about:3.3248,state:0},
    {url:'../../static/images/icon/coin-gram.png',name:'GRA',zhangfu:+121.13,price:68.3223022,about:3.3248,state:1},
    {url:'../../static/images/icon/coin-eth.png',name:'ETH',zhangfu:+12.83,price:68.25232,about:3.3248,state:1},
    {url:'../../static/images/icon/coin-bat.png',name:'BAT',zhangfu:-122.03,price:12.25322232,about:3.3248,state:0},
    {url:'../../static/images/icon/coin-etc.png',name:'ETC',zhangfu:-12.13,price:68.253232,about:3.3248,state:0},
    {url:'../../static/images/icon/coin-bat.png',name:'BAT',zhangfu:-9.03,price:68.253232,about:3.3248,state:0}
]
// slice
let result1 = data.slice().sort((a, b) => a.zhangfu - b.zhangfu) // 
let result2 = data.slice().sort((a, b) => b.zhangfu - a.zhangfu) // 

var drawerList = [
    {url:'../../static/images/icon/coin-etc.png',name:'ETC',zhangfu:+122.33,price:228.253,about:3.3248,state:1},
    {url:'../../static/images/icon/coin-bat.png',name:'BAT',zhangfu:-12.20,price:68.53,about:3.3248,state:0},
    {url:'../../static/images/icon/coin-gram.png',name:'GRA',zhangfu:+121.13,price:68.3223022,about:3.3248,state:1},
    {url:'../../static/images/icon/coin-eth.png',name:'ETH',zhangfu:+12.83,price:68.25232,about:3.3248,state:1},
    {url:'../../static/images/icon/coin-bat.png',name:'BAT',zhangfu:-122.03,price:12.25322232,about:3.3248,state:0},
    {url:'../../static/images/icon/coin-etc.png',name:'ETC',zhangfu:-12.13,price:68.253232,about:3.3248,state:0},
    {url:'../../static/images/icon/coin-bat.png',name:'BAT',zhangfu:-9.03,price:68.253232,about:3.3248,state:0},
]

function sortList(a, b) {
    return b.zhangfu - a.zhangfu
}
drawerList.sort(sortList)
console.log(drawerList)

drawerList.sort((a, b) => a.zhangfu - b.zhangfu)

drawerList.sort ((hr class= b) = > {return a.zhangfub.zhangfu;})


// 
drawerList.sort((a, b) => {
    return a.zhangfu-b.zhangfu
});

// 
drawerList.sort((a, b) => {
    return b.zhangfu-a.zhangfu
});

omnipotent sort and power, don't think about that bunch of sorting methods

drawerList = ary.sort((a, b) => a.zhangfu - b.zhangfu)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b34adf-2bf4d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b34adf-2bf4d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?