I have the following data structure:
var array = [
2016-11-24: Object,
2016-11-25: Object,
2016-11-26: Object,
2016-11-27: Object,
2016-11-28: Object
]
I want to sort the array from oldest data to newest but I'm having some trouble getting it to work. I been following this resource (Sort Javascript Object Array By Date) but the array won't sort.
I believe the object may be affecting this but I'm not sure of how to use sort() when arrays have objects inside of them.
Anything that I'm missing?
Edit:
More information. I'm building this through an .each() function that looks like this:
var retentionValues = [];
jQuery.each(results.values(), function( a, b ) {
var retentionData = {};
//Go deeper into the object under each data
$.each(b, function(c, d){
//Add People values into object
if (c === "first") {
retentionData["People"] = d;
} else { //Add values for specific days or weeks
//Go into object under counts
$.each(d, function(e, f){
retentionData["Retention Day " + e] = f;
})
}
})
//Push dates into array and create object for data
retentionValues[a] = retentionData;
});
I need the key of the array to be the date since I'm passing this to another function but I need to sort the data before then.