Tell us what’s happening:
Describe your issue in detail here.
[Why cant we use dot notation here instead of square bracket notation]
for example - usersObj.user.online gives error why though ?
**Your code so far**
function countOnline(usersObj) {
// Only change code below this line
let onlineCounter = 0;
for (let user in usersObj){
if(usersObj[user].online === true){
onlineCounter++;
}
}
return onlineCounter;
// Only change code above this line
}
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36
Challenge: Iterate Through the Keys of an Object with a for…in Statement
You use dot notation when you literally know the name of the property.
You use bracket notation when the property you want to access is stored in a variable.
// here you look for a property "user":
console.log(usersObj.user)
// here you look for a property "Alan" or "Jeff" or "Sarah",
// depending on what the variable "user" evaluates to
console.log(usersObj[user])