美文网首页让前端飞
js数组操作,实现日期排序

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

作者: jia林 | 来源:发表于2018-12-30 18:08 被阅读0次

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

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

相关文章

网友评论

    本文标题:js数组操作,实现日期排序

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