hasOwnProperty()
method and the other uses the in
keyword. If we have an object users
with a property of Alan
, we could check for its presence in either of the following ways:
users.hasOwnProperty('Alan');
'Alan' in users;
// both return true
users
, with some users in it and a function isEveryoneHere
, which we pass the users
object to as an argument. Finish writing this function so that it returns true
only if the users
object contains all four names, Alan
, Jeff
, Sarah
, and Ryan
, as keys, and false
otherwise.
users
object only contains the keys Alan
, Jeff
, Sarah
, and Ryan
testString: assert('Alan' in users && 'Jeff' in users && 'Sarah' in users && 'Ryan' in users && Object.keys(users).length === 4, 'The users
object only contains the keys Alan
, Jeff
, Sarah
, and Ryan
');
- text: The function isEveryoneHere
returns true
if Alan
, Jeff
, Sarah
, and Ryan
are properties on the users
object
testString: assert(isEveryoneHere(users) === true, 'The function isEveryoneHere
returns true
if Alan
, Jeff
, Sarah
, and Ryan
are properties on the users
object');
- text: The function isEveryoneHere
returns false
if Alan
, Jeff
, Sarah
, and Ryan
are not properties on the users
object
testString: assert((function() { delete users.Alan; delete users.Jeff; delete users.Sarah; delete users.Ryan; return isEveryoneHere(users) })() === false, 'The function isEveryoneHere
returns false
if Alan
, Jeff
, Sarah
, and Ryan
are not properties on the users
object');
```