I am working on a JavaScript project that involves objects.
Object {HIDDEN ID: "06/03/2014", HIDDEN ID: "21/01/2014"}
My goal is to create a new object where the dates are sorted in descending order.
Here's an example of what I want:
SortedObject {"HIDDEN ID" : "21/01/2014", "HIDDEN ID" : "06/03/2014"}
I have knowledge of how to achieve this with an array, but I'm facing challenges iterating through objects to sort by date.
Any assistance would be greatly appreciated.
UPDATE:
This is my current code snippet.
for(var x=0; x<folderList.length; x++){
retrieveAllFilesInFolder(folderList[x], function(){
var arr = [];
for(var i in fileListObj) {
var d = fileListObj[i].split("/");
arr.push({"id": i, "date":(new Date(d[2],d[1]-1,d[0]))});
}
arr.sort(function(a,b) { return a.date < b.date;});
console.log(arr);
});
}
However, the output is not sorted by date as intended.
Object 1 id: "hiddenID1", date: Mon Nov 18 2013 00:00:00 GMT+0000 (GMT Standard Time)
Object 2 id: "hiddenId2", date: Thu Mar 06 2014 00:00:00 GMT+0000 (GMT Standard Time)
Object 3 id: "hiddenId3", date: Thu Sep 05 2013 00:00:00 GMT+0100 (GMT Daylight Time)