`
Found a tiny mistake in the hint section of this challenge.
function isEveryoneHere(obj) {
// change code below this line
if(users.hasOwnProperty(‘Alan’,‘Jeff’,‘Sarah’,‘Ryan’)) {
return true;
}
return false;
// change code above this line
}
Instead of
if(users.hasOwnProperty(‘Alan’,‘Jeff’,‘Sarah’,‘Ryan’)) {
return true;
}
Correct code should be
if(obj.hasOwnProperty(‘Alan’,‘Jeff’,‘Sarah’,‘Ryan’)) {
return true;
}
Same for Solution-2.
function isEveryoneHere(obj) {
return (obj.hasOwnProperty(‘Alan’,‘Jeff’,‘Sarah’,‘Ryan’)) ? true : false;
}
`
Yeah, that’s totally wrong – thank you for picking up on it. I think it has been fixed, but at the minute the fix isn’t live, hopefully should be soon!
checking property exist in object or not
var person = {
name: 'amal'
};
console.log(person.hasOwnProperty('name'));
it will produce result as true
As you know object has property and value.
this hasOwnProperty is a method which is used to check whether the property
is there or not . it can not use for checking the value of object . it will return either true or false.
it can only one argument at a time
How to check whether property exist or not if that is the collection of many object stored in an array ?
var person = {[
name: 'amal'
],
[
name: 'John'
],[
name: 'amal',age:50
],
};
now if you want to know whether property is stored in an object you have to provide index of the array where that specific object is stored
console.log(person[1].hasOwnProperty('name')) => true
console.log(person[1].hasOwnProperty('age')) => false
console.log(person[2].hasOwnProperty('age')) => true
Just to be clear, hasOwnProperty only takes one argument.
Hi, thank you for this but there is a syntax mistake in the hint for that challenge, that’s what the OP was talking about, they weren’t asking how to use the hasOwnProperty
function.
Sry I did not check the challenge. I only tried to explain hasOwnProperty method
1 Like