How can I get the last object from an array of identical objects. I attached the code. I will appreciate any help. Thank you!
Input
[
{name:'Sam', count:3},
{name:'Sam', count:5},
{name:'Sam', count:8},
{name:'Jill', count:7},
{name:'Jill', count:6},
]
Output
[
{name:'Sam', count:8},
{name:'Jill', count:6},
]
const result = Array.from(yourArray.reduce((result, object) => { result.set(object.name, object); return result; }, new Map()).values());. See the documentation.