JavaScript for/of Statement

Iterate (loop) over the values of an array

Definition and Usage

The for...of statements combo iterates (loops) over the values of any iterable.

The code block inside the loop is executed once for each value.

See Also:

JavaScript Tutorial: The JavaScript for...of Tutorial

Syntax

for (x of iterable) {
  code block to be executed
}

Parameters

Parameter Description
x Required.
For every iteration the value of the next property is assigned to x.
iterable Required.
Anything that has iterable properties.

JavaScript Loop Statements

StatementDescription
breakBreaks out of a loop
continueSkips a value in a loop
whileLoops a code block while a condition is true
do...whileLoops a code block once, and then while a condition is true
forLoops a code block while a condition is true
for...ofLoops the values of any iterable
for...inLoops the properties of an object

Browser Support

for..of is an ECMAScript6 (ES6) feature.

ES6 (JavaScript 2015) is supported in all modern browsers:

Chrome Edge Firefox Safari Opera
Yes Yes Yes Yes Yes
for..of is not supported in Internet Explorer 11 (or earlier).