Looking to find a way to check if a similar object already exists in an array of objects. Specifically, I want to know if there is an object with the same make and model properties (Ford Focus):
{
make: 'Ford',
model: 'Focus',
color: 'red',
year: 2016
}
within 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 am hoping for an efficient ES6 solution but open to using lodash as well. While lodash’s _.some function seems like it could work, it either matches the whole object or only one property. I am also looking for functionality similar to _.pullAllWith, where I can remove all objects that have specific properties (in this case, delete all objects containing Ford Focuses).