Following is dynamic array in TypeScript and I want to sort it by activation date in descending order.
notificationList = [];
notificationList = [ {"Id:11", "ActivationDate":"29-Jan-2018"},
{"Id:21", "ActivationDate":"22-Jan-2018"},
{"Id:8", "ActivationDate":"01-Feb-2018"},
{"Id:10", "ActivationDate":"25-Jan-2018"},
{"Id:12", "ActivationDate":"24-Jan-2018"},
{"Id:05", "ActivationDate":"28-Jan-2018"},
{"Id:04", "ActivationDate":"24-Jan-2018"},
]
I am sorting using below code but it's not giving me expected output.
this.notificationList = this.notificationList.sort(function(a, b): any {
const dateA = new Date(a['ActivationDate']);
const dateB = new Date(b['ActivationDate']);
console.log('dateA -' + dateA);
console.log('dateB -' + dateB);
console.log(dateB > dateA);
return dateB > dateA; //sort by date decending
});
Any suggestion or input ?