Tell us what’s happening:
Describe your issue in detail here.
In the example code, I’m not understanding why we write arr[i] in the console.log.
How is [i] related to the array?
I understand that we initialize the loop with i = 0, the condition being i < arr.length, which to me means that the loop will continue to go until i < arr.length is no longer true, and the final expression i++ will make sure that the loop will not continue past i = 4 as the length of the array is (all elements - 1) due to arrays indexing at the start at 0.
I just can 't wrap my head around why we’re using bracket notation on the [i] in console.log(arr[i]);
const arr = [10, 9, 8, 7, 6];
for (let i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
Your code so far
// Setup
const myArr = [2, 3, 4, 5, 6];
// Only change code below this line
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36
Challenge: Iterate Through an Array with a For Loop
Link to the challenge: