I need help sorting an array of objects by the most recent created_at value while maintaining the entire object in that order. Currently, my code only returns the create_at value instead.
How can I adjust the map function to avoid separating the created_at value from the rest of the object?
var notes = [
{
country: "Angola",
denomination: 50,
currency: "Kwanzas",
issue_date: 2012,
created_at: "2017-07-20T18:41:15.000Z",
updated_at: "2019-07-20T18:41:15.000Z"
},
...
]
var dateMap = notes.map(note => note.created_at.substring(0,10)).sort().reverse()
The desired result should look like this:
dateMap = [
{
country: "Angola",
denomination: 50,
currency: "Kwanzas",
issue_date: 2012,
created_at: "2017-07-20T18:41:15.000Z",
updated_at: "2019-07-20T18:41:15.000Z"
},
...
]