There are multiple ways to loop through all elements of an array in JavaScript.

Let us say you have got the following array:

const fruits = ['🍊', '🍋', '🥝', '🥭', '🍑', '🍒']

Array.forEach() method

The forEach() method calls a callback function once for each element in an array:

fruits.forEach(fruit => console.log(fruit))

// 🍊
// 🍋
// 🥝
// 🥭
// 🍑
// 🍒

for...of statement

The for...of statement can be used to iterate through the values of an iterable object such as arrays, strings, maps, NodeLists, and more in JavaScript.

for (const fruit of fruits) {
    console.log(fruit)
}

for loop

Finally, the last way to loop through an array in JavaScript is by using the traditional for loop:

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