Question about looping through an instance

Hello campers, I have a question about checking the properties of an instance.

let ownProps = [];
let prototypeProps = [];

for (let property in duck) {
  if(duck.hasOwnProperty(property)) {
    ownProps.push(property);
  } else {
    prototypeProps.push(property);
  }
}

console.log(ownProps);
console.log(prototypeProps);

Why do I have to check with the if statement if the duck has the property, even though I’m looping through the properties of duck?

I would check the first sentence on MDN for this method

1 Like

Oh, thank you, didn’t realize lol

1 Like

MDN is a great place to check - it’s got lots of cool details

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.