Lets say I have an object
var person = [{
name: 'true',
city: 'false'
}]
and I have a predefined list of property names I would like to check against
let props = ['name', 'address']
How can I use lodash _.includes to check?
I've tried variations of the following to no avail, all return false
_.includes(person, [props]);
_.includes(person, 'name');
_.includes([person], 'name');
-- UPDATED -- Given your updated description, this is what the code will look like to get the results you desire.
const person = [{
name: 'true',
city: 'false'
}];
const props = ['name','address'];
let found = [];
Object.keys(person[0]).forEach(key => {
if(props.includes(key)) found.push(key)
});
// Found now contains ['name']
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments