Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Dimitris Karatsoulas5,788 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 Parker228,039 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