js 对日期进行排序

let data = [
            {
                count:"8",
                name: "21-09"
            },{
                count:"8",
                name: "20-11"
            },{
                count:"8",
                name: "20-12"
            },{
                count:"8",
                name: "21-01"
            }
        ]
data.sort(function (a,b){
            return a.name > b.name ? 1 : -1   //升序  < 降序
        })
        console.log(data);  //(4) [{…}, {…}, {…}, {…}]
                              0: {count: '8', name: '20-11'}
                              1: {count: '8', name: '20-12'}
                              2: {count: '8', name: '21-01'}
                              3: {count: '8', name: '21-09'}
                              length: 4
                              [[Prototype]]: Array(0)
                         

 

 

 

    原文作者:比较菜的Curry
    原文地址: https://blog.csdn.net/weixin_51523667/article/details/120901524
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞