按日期时间进行排序

data:[

{

text:"广东省",

time:"2019-02-21 02:39:50",

},

{

text:"安徽省",

time:"2019-02-21 02:30:43"

},

{

text:"湖南省",

time:"2019-02-21 02:19:02",

},

{

text:"山西省",

time:"2019-02-21 02:05:32",

},

]

 

1.

data.sort(function(a, b) {

return a.time - b.time;

});

2

data.sort(function(a, b) {

return a.createtime > b.createtime ? 1 : -1;

})

你可能感兴趣的:(javaScript)