Middle brackets [ ] or dot to get obj value?

Tell us what’s happening:
challenge URL:

there are two methods fail to access the online value in for…in loop

  1. user.online: I think the property in the user name has included in the user. Therefore I try to get value by user.online
  2. usersObj.user.online: After cheat, I try to access online by dot again, but it fails. I can’t figure out the reason.

I’ve relearned the object from js basic, but I can’t find the related information about the two issues.

Your code so far


function countOnline(usersObj) {
// Only change code below this line
let result = 0;
for (let user in usersObj) {
  if (usersObj[user].online === true) {
    result++;
  }
}
return result;
// 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/85.0.4183.102 Safari/537.36.

Challenge: Iterate Through the Keys of an Object with a for…in Statement

Link to the challenge:

user is a variable of value of a string, it’s not the object with the online property

again, user is a variable, using dot notation you are asking for a variable literally named user, to use the value inside the variable you need to use bracket notation