Dimitris Karatsoulas5,787 Points
How can we access the properties' names?
Hello, I was wondering if there's a way we can access each property's name so that we can code it to get printed just like each property's value instead of explicitly hard coding the names in our HTML output.
Steven Parker203,717 Points
You can iterate through the properties if you want ("
for (var property in student) ...") and then use bracket notation instead of dot notation to access the value ("
student[property]"). But you should be aware of some behavioral differences that will occur:
- if a property is missing, it will be silently omitted where the original will show the property as "undefined"
- if any extra properties are added, they will be listed where the original would show only the intended ones
- the order that the properties are listed is no longer guaranteed