Iterate Through the Keys of an Object with a for...in Statement.1

Iterate Through the Keys of an Object with a for...in Statement.1
0.0 0

#1

let users = {
  Alan: {
    age: 27,
    online: false
  },
  Jeff: {
    age: 32,
    online: true
  },
  Sarah: {
    age: 48,
    online: false
  },
  Ryan: {
    age: 19,
    online: true
  }
};

function countOnline(obj) {
  // change code below this line
  let i=0;
  for(let user in obj){
    if(obj.user.online == true){
      i++;
    }
  }
  return i;
  // change code above this line
}

console.log(countOnline(users));

#2

whats wrong in this?


#3

When you are referring to a computed key such as referring a key using variable or expression etc…

Use obj[key] instead of obj.key.

So this line is incorrect
obj.user.online