Nested Oject iteration in For in loop

We've defined a function,  `countOnline` ; use a for...in statement within this function to loop through the users in the  `users` object and return the number of users whose  `online` property is set to  `true` .

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 x1=0;
for(let i in obj)
{
  
  if(i.online==true)
  {
x1++;
  }
}
return x1;
  // change code above this line
}

console.log(countOnline(users));//

please help me as i am not able access online property.

i will be the names. So it’s not i.online, but obj[i].online.

1 Like

``
Thank You @Blauelf:smile: