in this challenge i have a big doubt i get the own property topic but i have a problem with the loop example for add the own properties to the array
this is the example:
let ownProps = [];
for (let property in duck) {
if(duck.hasOwnProperty(property)) {
ownProps.push(property);
}
}
console.log(ownProps); // prints [ "name", "numLegs" ]
exatly how works this because in my mind it should copy just one property of the object in the array because when i change property for example to name in the next loop it will see that the condition is true and will end the loop-
property is an example for x property? or this code must have property in “let (property)” for copy all properties?
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/understand-own-properties/