I am unable to sort an array by date. I tried many different things but couldn't get it to work. An array consists of objects with a last_updated field that has a value formatted like this: 24/1/2021 @ 13:21:2.
last_updated
24/1/2021 @ 13:21:2
I tried sorting the array before executing .map():
.map()
chats.sort(function (a, b) { return ( new Date(b.last_update) - new Date(a.last_update) ); });
This does not work and I honestly don't know why. Is this because of the @ in the date?
@
Try this:
chats.sort(function (a, b) { return new Date(b.last_update).getTime() - new Date(a.last_update).getTime(); });
1.4m articles
1.4m replys
5 comments
57.0k users