I have an array of objects which I am needing to check if a similar object already exists in the array. For example, is there an object that has the same make and model properties (Ford Focus):
{
make: 'Ford',
model: 'Focus',
color: 'red',
year: 2016
}
in this array?
[
{
make: 'Ford',
model: 'Focus',
color: 'blue',
year: 2008
},
{
make: 'Ford',
model: 'Mustang',
color: 'red',
year: 2011
},
{
make: 'Chevy',
model: 'Malibu',
color: 'blue',
year: 2012
},
{
make: 'Ford',
model: 'Focus',
color: 'black',
year: 1999
}
]
I'd prefer an ES6 method but can use lodash as well. Lodash has _.some but from what I can tell, it matches the whole object (not just the specific properties needed) or only one property. Additionally, I need something like _.pullAllWith where I can remove all objects that contain those specific properties (i.e. delete all objects that contain Ford Focuses).