# freeCodeCamp Challenge Guide: Iterate Through the Keys of an Object with a for...in Statement

**URL:** <https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-iterate-through-the-keys-of-an-object-with-a-for-in-statement/301162>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [August 3, 2019, 5:44am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-iterate-through-the-keys-of-an-object-with-a-for-in-statement/301162 "2019-08-03T05:44:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [August 3, 2019, 5:44am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-iterate-through-the-keys-of-an-object-with-a-for-in-statement/301162/1 "2019-08-03T05:44:41Z")

</div>

# [Iterate Through the Keys of an Object with a for…in Statement](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-the-keys-of-an-object-with-a-for---in-statement)

* * *

## Problem Explanation

- Note: `dot-notation` will cause errors in this challenge.
- `[square-bracket]` notation must be used to call a variable property name.
- The following code will not work.

* * *

## Hints

### Hint 1:

```javascript
for (let user in obj) {
  if (obj.user.online === true) {
    //code
  }
}

```

### Hint 2

- Example 2 demonstrates how using `[square-bracket]` notation the code will be executed.

```javascript
for (let user in obj) {
  if (obj[user].online === true) {
    //code
  }
}

```

* * *

## Solutions

> **Solution 1 (Click to Show/Hide)**
>
> ```javascript
> 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
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:55pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-iterate-through-the-keys-of-an-object-with-a-for-in-statement/301162/6 "2021-06-01T18:55:13Z")

</div>


