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! While you're at it, check out some resources Treehouse students have shared here.
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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Thomas Ma](https://secure.gravatar.com/avatar/3d18e261f1ac6b0966a387800cec9510?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Thomas Ma
15,199 PointsUse a for...in loop to log each of the property names of the composer object to the console.
help
const composer = {
name: 'Edward Ellington',
nickname: 'Duke',
genres: ['jazz', 'swing'],
instrument: 'piano'
};
2 Answers
![Ryan Groom](https://secure.gravatar.com/avatar/b8efae51bc92cad353f2e631a821308e?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ryan Groom
18,674 PointsThomas Ma It is as simple as the following:
for (let property in composer) {
console.log(property);
}
Where 'property' can be set to any name you see fit and 'composer' references the variable name of the object you created.
![Brandon White](https://uploads.teamtreehouse.com/production/profile-photos/10746138/micro_4228B6A1-B7B6-47B8-9D23-EB9C488C56CC.jpg)
Brandon White
Full Stack JavaScript Techdegree Graduate 34,662 PointsYou are correct, Ryan.
Although, you’ll generally want to declare the ‘property’ variable with either the let or const keyword. Otherwise, I’m pretty sure the variable gets defined on the global object (which is typically not what you’ll want).
So typically it’ll go for (let property in composer) {...}
instead of for (property in composer) {...}
.
![Thomas Ma](https://secure.gravatar.com/avatar/3d18e261f1ac6b0966a387800cec9510?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Thomas Ma
15,199 PointsI need the answer
![shahzaib rafiq](https://uploads.teamtreehouse.com/production/profile-photos/11535391/micro_profile.jpg)
shahzaib rafiq
Courses Plus Student 3,001 PointsHello, If you want to print the property name or key like 'name' and 'nickname' of the object composer by using 'for in' loop the syntax is for ( var propertyName in composer ){ console.log(propertyName); } this just gives you access to the key name.
However, if you want to access the property value like 'Edward Ellington' and 'Duke' you use "square bracket notation" Like for ( var propertyName in composer ){ console.log(composer[propertyName]); } in fact, the only way to access an object property using the 'for in' loop is with the bracket notation.
Brandon White
Full Stack JavaScript Techdegree Graduate 34,662 PointsBrandon White
Full Stack JavaScript Techdegree Graduate 34,662 PointsHi Thomas Ma,
What is it specifically that you need help with?
Do you not understand the for...in syntax? If so, here’s a link to an article on how to use it.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in