Basic Data Structures: Iterate Through the Keys of an Object with a for...in Statement Apex

Tell us what’s happening:
I am having difficulty developing a code for this problem

Your code so far

       function countOnline(usersObj) {
  // Only change code below this line
for (let prop in usersObj) {
 console.log(prop[true])  
}
  // Only change code above this line
} 

function countOnline(usersObj) {
 // Only change code below this line
for (let prop in true) {
console.log(prop[true])  
}
 // Only change code above this line
} 

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15.

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

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Thank you for your assistance ieahleen

Unfortunately I am having difficulty viewing your changes. Can you help me navigate to those changes so that I can view them?

This might be a bit vague, not sure.

function countOnline(usersObj) {
  for (let prop in usersObj) {
    console.log(typeof prop) // String
  }
}

Example:

const userObj = {
  John: {
    lastName: 'Doe' 
  }
}

console.log(userObj['John']) // { lastName: 'Doe' }
console.log(userObj['John'].lastName) // Doe

// Or 

const name = 'John';

console.log(userObj[name]) // { lastName: 'Doe' }
console.log(userObj[name].lastName) // Doe

Thank you lasjorg for your response.

I don’t understand… are you providing a solution?

No, we don’t do that here. I did say it might be a bit vague.

  1. I show that prop is a string in the for…in loop.

  2. I show how to get to properties on an object (using a string).

See if you can’t tie it back to the challenge.


A bit more help, maybe don’t look until you have thought about it some more.

function countOnline(usersObj) {
  for (let prop in usersObj) {
    console.log(usersObj[prop])
  }
}

I just formatted your code

unformatted code:

formatted code: