0

So basically I have an array like so:

const data = [
    { name: "John Doe", dob: "2021-07-06T09:45:07.125Z" },
    { name: "Jane Doe", dob: "2021-07-06T09:44:34.121Z" },
    { name: "John Wick", dob: "2021-07-06T09:50:17.313Z" }
];

I need to display this data in a table, so I am mapping through the array and creating a row, but I need the youngest person to be first. I tried doing like .sort() but couldn't get it to work

{data.sort((a,b) => b.dob- a.dob
BranOIE
  • 400
  • 4
  • 19
  • 2
    "I tried doing like .sort()" Could you show us the code you tried? – phuzi Jul 07 '21 at 08:55
  • Does this question help? https://stackoverflow.com/q/10123953/14032355 – ikhvjs Jul 07 '21 at 08:56
  • @phuzi I tried `data.sort((a,b)=> new Date(b.date) - new Date(a.date))` – BranOIE Jul 07 '21 at 09:07
  • You need to add that code to the question and explain what you're expecting and what actually happens. Could you also put some sample dates in the example rather than `"Date in ISO format"` – phuzi Jul 07 '21 at 09:09

0 Answers0