What are "for loops" in JavaScript?

Jahkamso - Aug 23 - - Dev Community

Imagine you're in a hall (a ball room), all the chairs are disorganised, and your task is to arrange them. Where would you start? Obviously, you'll either go row by row or column by column, but it's going to be sequential/orderly.

The same is true when it comes to "for loops". It's basically a way to go through a list of data and present them one after the other till you get to the end.

An example of "for loops":

const fruits = ["Apple", "Banana", "Cherry", "Date", "Elderberry"];

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

In the example above, there's an array of data containing fruit names. The "for loop" goes through all of them and prints them out in the console, one after the other.

This explanation is short, but I hope you understand "for loops" better.

. . . . .
Terabox Video Player