美文网首页JavaScript 进阶营
【JavaScript】二维数组根据字段排序

【JavaScript】二维数组根据字段排序

作者: level | 来源:发表于2019-11-29 15:24 被阅读0次
    let data = [
        {alarming: 1, count: 6},
        {alarming: 0, count: 0},
        {alarming: 1, count: 1},
        {alarming: 0, count: 12},
        {alarming: 1, count: 3},
        {alarming: 0, count: 0},
        {alarming: 0, count: 5}
    ];
        
    data.sort((x, y) => {
        if(x.alarming == y.alarming) {
            return y.count - x.count;
        }
    
        return y.alarming - x.alarming;
    });
    

    相关文章

      网友评论

        本文标题:【JavaScript】二维数组根据字段排序

        本文链接:https://www.haomeiwen.com/subject/nglgwctx.html