Files
Randell Dawson 1494a50123 fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles
* fix: added 3 dashes line before prob expl
* fix: added 3 dashes line before hints
* fix: added 3 dashes line before solutions
2019-07-24 13:29:27 +05:30

891 B

title
title
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.


Solutions

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