What is the best way to do? I am interested in lodash methods as well if there is any better approach
var myObj = {
name: 'John',
age: 20,
sex: male
}
I like to see whether myObj have 'name' and 'age' keys
My Approach - it works fine
var myObj = {
name: 'John',
age: 20,
sex: 'male'
}
var value;
function result() {
if (myObj.hasOwnProperty('name') && myObj.hasOwnProperty('age')) {
value = true;
} else {
value = false;
}
}
result();
console.log(value);
I can also use ('key' in myObj)
But actually I has an object which is quiet big and need to check if they have particular keys. Looking for any better approach