Check for emptiness
importance: 5
Write the function isEmpty(obj)
which returns true
if the object has no properties, false
otherwise.
Should work like that:
let schedule = {};
alert( isEmpty(schedule) ); // true
schedule["8:30"] = "get up";
alert( isEmpty(schedule) ); // false
Just loop over the object and return false
immediately if there’s at least one property.
function isEmpty(obj) {
for (let key in obj) {
// if the loop has started, there is a property
return false;
}
return true;
}