我有一个对象数组,我想按日期排序。我的日期格式如下,具有属性 - created_at: "2014-09-26 19:27:43"
.
如果有人能指出我正确的方向,那就太好了。
最佳答案
使用Date
对象进行比较,使用Array.prototype.sort()
进行排序。
var array = ["2014-09-26 19:27:43","2014-09-26 19:27:42","2014-09-23 19:27:43"];
var sortedArray = array.sort(function(a,b){
return new Date(a) - new Date(b);
});
document.write(sortedArray);
关于javascript - 按日期对对象数组进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27692611/