English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript for...of statement

 JavaScript Statements and Variable Declarations

for...ofThe statement creates a loop to traverse an iterable object, including: built-in String, Array, array-like objects (such as arguments or NodeList), and user-defined iterable objects.

It calls a custom iteration hook that contains statements to be executed for each different property value of the object.

Both for...in and for...of statements iterate over certain content. The main difference between them lies in the content they iterate over:

  • for...in - Traversal of the enumerable properties of an object in any order

  • for...of - Traversal of iterable objects defines the data to be traversed, creates an iteration loop on iterable objects (including Array, Map, Set, String, TypedArray, arguments object, etc.), calls a custom iteration hook, and executes statements for each different property value.

Syntax:

for (variable of iterable) {
 //Statement to be executed 
}
let iterable = [10, 20, 30, 40, 50];
for (let x of iterable) {
    document.write(x);
}
Test and See‹/›

Browser Compatibility

The numbers in the table specify the first browser version that fully supports the for ... of statement:

Statement
for...of3813258Not Supported

Parameter Value

ParameterDescription
variableAssign the values of different properties tovariable
iterableIterate over objects whose properties are iterable

Technical Details

JavaScript Version:ECMAScript 1

Related References

JavaScript Reference:JavaScript for...in Statement

 JavaScript Statements and Variable Declarations