Update iterate-through-an-array-with-a-for-loop (#41742)
* Update iterate-through-an-array-with-a-for-loop * Update iterate-through-an-array-with-a-for-loop Add space around minus for better readablilty. * Update iterate-through-an-array-with-a-for-loop * Update iterate-through-an-array-with-a-for-loop * Update iterate-through-an-array-with-a-for-loop.md
This commit is contained in:
committed by
GitHub
parent
a962d6afd4
commit
617f7b07e9
@ -18,7 +18,7 @@ for (var i = 0; i < arr.length; i++) {
|
||||
}
|
||||
```
|
||||
|
||||
Remember that arrays have zero-based indexing, which means the last index of the array is `length - 1`. Our condition for this loop is `i < arr.length`, which stops the loop when `i` is equal to `length`. In this case the last iteration is `i === 4` i.e. when `i` becomes equal to `arr.length` and outputs `6` to the console.
|
||||
Remember that arrays have zero-based indexing, which means the last index of the array is `length - 1`. Our condition for this loop is `i < arr.length`, which stops the loop when `i` is equal to `length`. In this case the last iteration is `i === 4` i.e. when `i` becomes equal to `arr.length - 1` and outputs `6` to the console. Then `i` increases to `5`, and the loop terminates because `i < arr.length` is `false`.
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
Reference in New Issue
Block a user