📅  最后修改于: 2022-03-11 15:03:17.627000             🧑  作者: Mango
// Iterate Through the Keys of an Object
const usersObj = {
Alan: {
online: false,
},
Jeff: {
online: true,
},
Sarah: {
online: false,
},
};
function countOnline(usersObj) {
let count = 0;
for (let user in usersObj) {
if (usersObj[user].online === true) count++;
}
return count;
}
console.log(countOnline(usersObj));