I have a JavaScript object that looks like follows
testObj = {
1/10/2015: {},
2/10/2015: {},
3/10/2015: {},
4/10/2015: {},
29/09/2015: {},
30/09/2015: {}
}
Now, I'm trying to sort this such that the dates are arranged by date in increasing order. For that i've done the following
const orderedDates = {};
Object.keys(testObj).sort(function(a, b) {
return moment(moment(b, 'DD/MM/YYYY') - moment(a, 'DD/MM/YYYY')).format('DD/MM/YYYY');
}).forEach(function(key) {
orderedDates[key] = testObj[key];
})
rangeObj = orderedDates;
This however is not sorting the dates at all. It still returns the same exact object as testObj
. How do I sort the object based on date keys?