搜索
您的当前位置:首页正文

js数组操作,实现日期排序

来源:知库网

需求:根据时间倒序排列新闻列表

image.png
  let newList = [
            {title:'新闻',time:'2017-12-30'},
            {title:'新闻',time:'2018-09-30'},
            {title:'新闻',time:'2018-12-30'},
        ];
        newList.sort((a,b) => {
            return a.time > b.time ? 1 : -1;
        })
        console.log(newList)
image.png
Top