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 trialbrandonlind2
7,823 Pointsobject property values are showing up as undefined in a loop, any ideas as to why?
var students=[
{name: 'john',
age:20,
track: 'ios',
achievements: 40,
points: 200},
{name: 'tom',
age:21,
track: 'java',
achievements: 60,
points: 660},
{name: 'dave',
age:30,
track: 'nod.js',
achievements: 100,
points: 404},
{name: 'alex',
age:50,
track: 'javascript',
achievements: 30,
points: 303},
{name: '50',
age:90,
track: 'ruby',
achievements: 20,
points: 222}
];
for(var i=0; i< students.length; i+=1){
for(var prop in students[i]){
console.log( prop + ": " + students[prop])
}
}
```javascript
1 Answer
Tobias Helmrich
31,603 PointsHey there Brandon,
the problem is that you have an array but when you're trying to log the properties of the object to the console you're not specifying at which position of the array the object is. So you're basically trying to get the property of an array.
console.log( prop + ": " + students[prop])
If you add the index i before the property it should work fine. Like so:
console.log( prop + ": " + students[i][prop])
I hope that helps! :)
brandonlind2
7,823 Pointsbrandonlind2
7,823 Pointsthanks!