How Do You Use a for Loop on an Array ?
Problem
You want to iterate through all the values of an array-like object where order is important.
Solution
A for loop lets you iterate through the values of an array in numeric order.
The Code
Listing 8-1. Iterating Through an Array-Like Object with a For Loop
var alphaArray = ['a', 'b', 'c', 'e', 'd', 'e', 'f', 'g'];
var arrayLength = alphaArray.length;
for (let i = 0; i < arrayLength; i++){
console.log(alphaArray[i]); //returns a,b,c,d,e,f,g
}
How It Works
For loops are often used when iterating ...