Skip to content

JavaScript for...of Loop

Syntax

The for...of loop in JavaScript is used to iterate over iterable objects such as arrays, strings, or other collections.

for (element of iterable) {
// Code to execute for each element
}

Example

let fruits = ["Apple", "Banana", "Cherry"];
for (let fruit of fruits) {
console.log(fruit);
}
// Output:
// Apple
// Banana
// Cherry