I have an array containing an JS-object such as this:
const dataObjs = [
{
city: 'Venice',
name: 'Mr. Smith',
age: '42'
},
{
city: 'Venice',
name: 'Mrs. Carter',
age: '30'
},
{
city: 'Munich',
name: 'Mr. Mueller',
age: '30'
},
{
city: 'London',
name: 'Mr. Spaghetti',
age: '75'
}
]
const filterObj = {
age: '30'
}
/*const filterObj = {
age: '30',
city: 'Venice'
}
*/
const theAnswerIs = dataObjs
.filter(item => item.includes(filterObj))
If the filter object only contains one property, only the one property shall be returned (e.g. age = xxx). If two properties are passed, both properties should be searched (with an and operator). I suppose "include" doesn't work here, because item is no array... ?