I have an array, to simplify lets say persons with first, last, and age. I want to make a new array of all persons that have the same first name, same last name and same age. For example my starting array:
[
{id: 1, first: 'fred', last: 'smith', age: 21},
{id: 2, first: 'fred', last: 'smith', age: 21},
{id: 3, first: 'tom', last: 'smith', age: 21},
{id: 4, first: 'fred', last: 'smith', age: 32}
]
I would like to return the duplicates that match first/last/age:
[
{id: 1, first: 'fred', last: 'smith', age: 21},
{id: 2, first: 'fred', last: 'smith', age: 21}
]
I'm struggling with _.uniq to figure out how to do this, any help is appreciated.
.reduce()do what you want? Compare each item with the previous, and if they match, return the later?