--- id: 587d7daf367417b2b2512b7d title: Iterate Over All Properties challengeType: 1 forumTopicId: 301320 localeTitle: Итерация по всем свойствам --- ## Description
Теперь вы видите два вида свойств: own свойства и свойства prototype . Own свойства определяются непосредственно на самом экземпляре объекта. И prototype определены на prototype .
функция Bird (name) {
this.name = name; //собственность
}

Bird.prototype.numLegs = 2; // свойство прототипа

пусть утка = новая птица («Дональд»);
Вот как вы добавляете own свойства duck к массиву ownProps и свойства prototype для массива prototypeProps :
let ownProps = [];
let prototypeProps = [];

для (пусть свойство в утке) {
if (duck.hasOwnProperty (свойство)) {
ownProps.push (свойство);
} else {
prototypeProps.push (свойство);
}
}

console.log (ownProps); // печатает ["name"]
console.log (prototypeProps); // печатает ["numLegs"]
## Instructions
Добавьте все own свойства beagle в массив ownProps . Добавьте все свойства prototype Dog в массив prototypeProps .
## Tests
```yml tests: - text: The ownProps array should include "name". testString: assert(ownProps.indexOf('name') !== -1); - text: The prototypeProps array should include "numLegs". testString: assert(prototypeProps.indexOf('numLegs') !== -1); - text: Solve this challenge without using the built in method Object.keys(). testString: assert(!/\Object.keys/.test(code)); ```
## Challenge Seed
```js 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 ```
## Solution
```js function Dog(name) { this.name = name; } Dog.prototype.numLegs = 4; let beagle = new Dog("Snoopy"); let ownProps = []; let prototypeProps = []; for (let prop in beagle) { if (beagle.hasOwnProperty(prop)) { ownProps.push(prop); } else { prototypeProps.push(prop); } } ```