I have an array of objects which includes lastModifiedDate property in each object. I want to sort the array of objects according to lastModifiedDate property in ascending as well as descending order. If the dates are same then the sorting should be based on time of the date.
var completeData = [{name: 'xyz', lastModifiedDate: 1579329711458}, {name: 'abc', lastModifiedDate: 1579339014519}]
I have tried the below code to sort the above array.
For Ascending order:
completeData.sort(function(a, b){
return new Date( a.lastModifiedDate ) < new Date( b.lastModifiedDate );
});
For Descending order:
completeData.sort(function(a, b){
return new Date( a.lastModifiedDate ) > new Date( b.lastModifiedDate );
});