Зміст курсу
JavaScript Data Structures
1. Introduction and Prerequisites
2. Objects Fundamentals
3. Advanced Object Manipulation
JavaScript Data Structures
Challenge: hasOwnProperty() for Object Property Iteration
Task
Create a loop that iterates through the properties of an object and prints each property along with its value. However, you should only print properties that belong directly to the object, not those inherited from its prototype chain. Utilize the hasOwnProperty()
method to achieve this.
Expected output:
- Use a
for...in
loop to iterate through the object's properties. - Within the loop, check if each property is an own property of the object using
hasOwnProperty()
before logging it.
Все було зрозуміло?
Зміст курсу
JavaScript Data Structures
1. Introduction and Prerequisites
2. Objects Fundamentals
3. Advanced Object Manipulation
JavaScript Data Structures
Challenge: hasOwnProperty() for Object Property Iteration
Task
Create a loop that iterates through the properties of an object and prints each property along with its value. However, you should only print properties that belong directly to the object, not those inherited from its prototype chain. Utilize the hasOwnProperty()
method to achieve this.
Expected output:
- Use a
for...in
loop to iterate through the object's properties. - Within the loop, check if each property is an own property of the object using
hasOwnProperty()
before logging it.
Все було зрозуміло?