How can I filter an array down to all objects that might look similar by certain keys without knowing the value of those keys?
Imagine I have an object like this:
let list = [
{ name: 'Adam', age: '10', uniqueStuff: 'a'},
{ name: 'Brian', age: '2', uniqueStuff: 'b'},
{ name: 'Carley', age: '15', uniqueStuff: 'c'},
{ name: 'Adam', age: '2', uniqueStuff: 'd'},
{ name: 'Christy', age: '15', uniqueStuff: 'e'},
{ name: 'Adam', age: '10', uniqueStuff: 'f'},
]
I want the result to be:
let list = [
{ name: 'Adam', age: '10', uniqueStuff: 'a'},
{ name: 'Adam', age: '10', uniqueStuff: 'f'},
]
These may look like duplicates because they share the same name and age, but uniqueStuff is different. So I'm not trying to remove possible duplicates, but to get an array of all similar objects in the array.
Kind of like answering the question "how many kids do we have with the same names and same ages?"
This would be similar to MySQL's "having count(*) > 1" queries.
I'm having a really hard time searching for an answer or figuring out a LoDash method. Everything I find is about removing duplicates or getting only the duplicates so there's only 1 of each item. Instead, I want to get all the items that are duplicates and have duplicates. So each "match" in my array should have 2 or more items. For example, 2 or more 10-year old Adams, 2 or more 6-year-old Amys, and such.
Thanks in advance!
Carleyis changed toChristy?