# freeCodeCamp Challenge Guide: Iterate Over All Properties

**URL:** <https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-iterate-over-all-properties/301320>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [August 3, 2019, 12:40pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-iterate-over-all-properties/301320 "2019-08-03T12:40:42Z")\
**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, 12:40pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-iterate-over-all-properties/301320/1 "2019-08-03T12:40:42Z")

</div>

# [Iterate Over All Properties](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/object-oriented-programming/iterate-over-all-properties)

* * *

## Problem Explanation

The method is to use a `for-in-loop` to iterate through every property in the object. Inside the loop you then check if the property is a `own-property` or a `prototype` and place it in the `ownProps[]` array or the `prototypeProps[]` array. Remember to `push` properties to the `beagle` object and not the `Dog` object to pass all test cases.

* * *

## Solutions

> **Solution 1 (Click to Show/Hide)**
>
> ```javascript
> function Dog(name) {
> this.name = name;
> }
> 
> Dog.prototype.numLegs = 4;
> 
> let beagle = new Dog("Snoopy");
> 
> let ownProps = [];
> let prototypeProps = [];
> 
> // Add your code below this line
> for (let property in beagle) {
> if (Dog.hasOwnProperty(property)) {
> ownProps.push(property);
> } else {
> prototypeProps.push(property);
> }
> }
> 
> ```

---

<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:** [January 8, 2025, 3:58pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-iterate-over-all-properties/301320/2 "2025-01-08T15:58:41Z")

</div>

Closed on January 8, 2025, 3:58pm UTC


