So the lesson name is:
“Basic JavaScript: Iterate Through an Array with a For Loop”
And then they have this example:
var arr = [10, 9, 8, 7, 6];
for (var i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
I understand we have an array var arr = [10, 9, 8, 7, 6];
Then we have a ( for loop ) for (var i = 0; i < arr.length; i++) { // the code }
Now I understand how arrays work, and how the for loop works. But what I don’t understand is how arr[i] ads the value of i to the array. and how exactly it is adding the values of array if it has the value of i which is = 0 ?
So when we do this arr[i] in the for loop, what is happening here?
In the previous lessons they taught how to get an array’s value using bracket notation but they don’t explain it here.
I am stuck at this for 2 days now.
So when we do arr[i] are we getting the first item in the array?
Then because it’s inside a loop it will iterate though the array starting at 0 and the first time it will show the first item then the second time it will add numbers at position 0 with 1 right? and so on untill the condition is false
// Setup
Thank you, now it makes sense a little. But I’ll change the value of total to see what happens.
I still don’t know if this arr[i] has a name in Javascript.
It seems like some stuff have no name in Javascript so they skip the explanation part?