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

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Two-Dimensional Arrays

What does [i] stand for?

Im not sure what it means .

Justyna Szofinska
Justyna Szofinska
6,178 Points

This square bracket represent an array - multiple variable. When you create a loop with "i" variable you can put every number of the loop into "i". For example:

function createListItem(arr){
let items=''; 
for (let i=0; i<arr.length; i++) {
 items += arr[i];
}
....

arr[i] means that during the loop we create arr[0],arr[1],arr[2] and so on until the loop will end.

1 Answer

Daniel Riches
Daniel Riches
19,847 Points

I believe i stands for iteration. But within the bracket it corresponds to the array's index. So you're relating the loop iteration with the array index. For instance when i = 2, then the array index is also 2, i.e. array[2]