Categories
JavaScript Answers

How to loop through an array in JavaScript?

Spread the love

To loop through an array in JavaScript, we use a for-of loop.

For instance, we write

const colors = ["red", "green", "blue"];
for (const color of colors) {
  console.log(color);
}

to loop through the colors array with a for-of loop.

And we get the value being looped through with color.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.