Check if an Object has a Property
Summary
.hasOwnProperty
can be used to check if an object contains a certain p
Final Code
let users = {
Alan: {
age: 27,
online: true
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: true
},
Ryan: {
age: 19,
online: true
}
};
function isEveryoneHere(obj) {
if (
obj.hasOwnProperty("Alan") &&
obj.hasOwnProperty("Jeff") &&
obj.hasOwnProperty("Sarah") &&
obj.hasOwnProperty("Ryan")
) {
return true;
}
return false;
}