I got an array of objects which I want to sort by date. I've got the date formatted like this with a property - created_at: "2014-09-26 19:27:43"
.
If any one could point me in the right direction, that would be great.
I got an array of objects which I want to sort by date. I've got the date formatted like this with a property - created_at: "2014-09-26 19:27:43"
.
If any one could point me in the right direction, that would be great.
Use Date
objects for comparison and Array.prototype.sort()
to 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);