I have an array of data like so:
[
{id: 1, date: "2022-10-01T12:00:00.00", type: 1},
{id: 2, date: "2022-10-02T12:00:00.00", type: 1},
{id: 3, date: "2022-10-03T12:00:00.00", type: 2},
{id: 4, date: "2022-10-04T12:00:00.00", type: 2},
]
I'd like to filter this so that I get an array of objects that only includes objects with the most recent date
for each type
. So something like this:
[
{id: 2, dttm: "2022-10-02T12:00:00.00", type: 1},
{id: 4, dttm: "2022-10-04T12:00:00.00", type: 2},
]
I suspect there's a clever way to do this with the .reduce()
function, but I haven't quite figured that out yet.