I have the following nested object. I would like to iterate through every item (latest.sentTime) and then sort the object itself by "sentTime". So that the most recent message is on top. How can I achieve this?
In the following example, "0" and "1" need to be swapped basically, since "1" has a more recent "sentTime".
Array#map, iterate over the array to get latest.sentTimeArray#sort and Date, sort the itemsconst arr = [
{ latest: { sentTime: '2022-02-05T19:15:32.000Z' } },
{ latest: { sentTime: '2022-02-06T22:12:00.000Z' } }
];
const sentTimes = arr
.map(({ latest }) => latest.sentTime)
.sort((a, b) => new Date(b) - new Date(a));
console.log(sentTimes);