Thanks ahead for your help!
I'm trying to reorder some objects so the newest ordered product would be first. So looking at the data below, the new order should be (from newest to oldest) product2, product3, and then product1.
{
"candyResponse": {
"product1": {
"displayName": "Bubble Gum",
"imageURL": "https://dummyimage.com/200x200/000/ffffff.png&text=prod1?$146$",
"orderDate": {
"time": "11/03/2018"
}
},
"product2": {
"displayName": "Chocolate",
"imageURL": "https://dummyimage.com/200x200/000/ffffff.png&text=prod2?$146$",
"orderDate": {
"time": "03/05/2015"
}
},
"product3": {
"displayName": "Mints",
"imageURL": "https://dummyimage.com/200x200/000/ffffff.png&text=prod3?$146$",
"orderDate": {
"time": "09/20/2017"
}
}
}
}
I tweaked the code from Sorting an array of JavaScript objects but I was not successful. Tried three ways...
candyResponse.sort(function(a, b) {
return parseFloat(a.time) - parseFloat(b.time);
});
candyResponse.sort(function(a, b) {
return parseFloat(a.orderDate) - parseFloat(b.orderDate);
});
candyResponse.sort(function(a, b) {
return parseFloat(a.orderDate.time) - parseFloat(b.orderDate.time);
});
Thanks again for your help!