1array = [{
2 id: 1, name: "test1", date: "2020-01-05",
3 id: 2, name: "test2", date: "2020-01-02"
4 }]
5
6array.sort(function (a, b) {
7 var dateA = new Date(a.date), dateB = new Date(b.date)
8 return dateA - dateB
9});
10
11console.log(array) //array is now sorted by date
1array.sort(function(a,b){
2 // Turn your strings into dates, and then subtract them
3 // to get a value that is either negative, positive, or zero.
4 return new Date(b.date) - new Date(a.date);
5});
1 arr = arr.sort(function (a, b) {
2 var dateA = new Date(a.date_prop).getTime();
3 var dateB = new Date(b.date_prop).getTime();
4 return dateA < dateB ? 1 : -1;
5 });
6