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 trialAdam Maley
5,946 PointsWhy is Console.log(students[i]); Showing the name of a person in the array and not the number that var i= ?
Why is Console.log(students[i]); Showing the name of a person in the array and not the number that var i= ?
1 Answer
Martin Lecke
14,385 PointsWhen you write students[i]. The i inside the bracket represents a number in your loop. If your write
students[0]; // represent first value in the array
students[1]; // second
students[2]; // and third
The i variable increases for every loop iteration.
Jackson Monk
4,527 PointsJackson Monk
4,527 PointsBecause students[i] is saying get the array value of students[whatever number i is], and returns an array value. If you want to print out the value of i, just do console.log(i);