offline version v3


7 of 264 menu

for-of statement

The for-of construct creates a loop to iterate over an array.

Syntax

for (let variableForElement of array) { /* The iterated array elements will fall into the variableForElement one by one. */ };

Example

Let's iterate over the array elements and display them on the screen:

let arr = [1, 2, 3, 4, 5]; for (let elem of arr) { console.log(elem); }

Example

Let's make a loop iteration counter:

let arr = [1, 2, 3, 4, 5]; let i = 0; for (let elem of arr) { console.log(elem); i++; } console.log(i);

See also

enru