Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,176 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]