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
2
3var compareDate = (t1: Interface, t2: Interface) => {
4 var t1Date = new Date(t1.createDate);
5 var t2Date = new Date(t2.createDate);
6 return t1Date > t2Date ? -1 : 1;
7 };
8
9 arr = [...objectarr].sort(compareDate);
10
11
12
13
14