Iteration

Let's create an array with some car manufacturers:

var cars = ['Audi', 'Ferrari', 'Tesla'];

We can iterate through this array with foreach, for and also with for of.

foreach

Watch the YouTube video
cars.forEach(car => {
  console.log(car);
});

for

Watch the YouTube video
for (let i = 0; i < cars.length; i++) {
  const car = cars[i];
  console.log(car);
}

for of

Watch the YouTube video
for (const car of cars) {
  console.log(car);
}

reversed order

Watch the YouTube video

We can also iterate in reverse by using the for loop:

for (let i = cars.length - 1; i >= 0; i--) {
  const car = cars[i];
  console.log(car);
}