How to sort objects by date ascending order?

后端 未结 4 1584
孤街浪徒
孤街浪徒 2021-02-10 08:09

if I have a list of object:

var objectList= LIST_OF_OBJECT;

each object in the list contains three attributes: \"name<

4条回答
  •  别跟我提以往
    2021-02-10 08:54

    If your objects have the date information within a String field:

    yourArray.sort(function(a, b) { return new Date(a.date) - new Date(b.date) })
    

    or, if they have it within a Date field:

    yourArray.sort(function(a, b) { return a.date - b.date })
    

提交回复
热议问题