typescript Sort array of objects by date property value code example
Example 1: sort array by date typescript
array.sort((x, y) => +new Date(x.createdAt) - +new Date(y.createdAt));
Example 2: sort array of objects javascript by date
array.sort(function(a,b){
// Turn your strings into dates, and then subtract them
// to get a value that is either negative, positive, or zero.
return new Date(b.date) - new Date(a.date);
});