- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript for of Loop
JavaScript Loops
JavaScript for of Loop
The JavaScript
for ofloop is used to loop through the values of an array, a string, and other collections.
The for of loop gives you one value at a time.
You do not need an index or a counter, which makes it shorter and easier to read than a normal for loop.
Example
Example
javascript
let fruits = ["Apple", "Banana", "Mango"];
for (let fruit of fruits) {
console.log(fruit);
}In this example, the loop prints each fruit name.
The output is Apple, Banana and Mango.
