Looping Through Arrays

You can loop through arrays using various methods like for, forEach, and map.

Using for loop:

for (let i = 0; i < fruits.length; i++) {
  console.log(fruits[i]);
}

Using forEach:

fruits.forEach(fruit => {
  console.log(fruit);
});

Using map:

const upperFruits = fruits.map(fruit => fruit.toUpperCase());
← PrevNext →