INTRODUCTION TO ITERATION
In JavaScript, one of the simplest examples of iteration is a counting loop:
for (let i = 1; i <= 10; ++i) {
console.log(i);
}
Loops are a fundamental iterative tool because they allow you to specify how many iterations should occur and what should occur during each iteration. Each loop iteration will finish execution before another begins, and the order in which each iteration occurs is well-defined.
Iteration can occur over ordered collections of items. (Consider “ordered” in this context to imply there is an accepted sequence in which all the items should be traversed, with a definitive beginning and end item.) In JavaScript, the most common example of this ordered collection is an array.
let collection = ['foo', 'bar', 'baz'];
for (let index = 0; index < collection.length; ++index) {
console.log(collection[index]);
}
Because an array has a known length, and because each item in that array can be retrieved...