freeCodeCamp Challenge Guide: Iterate Over All Properties

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.


Solution 1 (Click to Show/Hide)
function Dog(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)) {
  } else {
1 Like