JavaScript for...of Statement
The for...of statement loops over the values of an iterable object, such as an array, string, Map, Set or NodeList, running a block of code for each value.
Description
The for...of statement runs a loop over the values of an iterable object. Iterables include arrays, strings, Map and Set objects, typed arrays, the arguments object, DOM collections such as NodeList, and generators. On each pass, the next value is assigned to the loop variable.
Declare the variable with const if you don't reassign it inside the loop, or let if you do; a new binding is created for each iteration. You can stop the loop early with break, skip to the next value with continue, and use await inside it in an async function. To loop over arrays with their index, use array.entries() with destructuring.
Don't confuse it with for...in, which loops over the keys of an object, including inherited ones, and is not meant for arrays. Plain objects are not iterable, so use Object.entries() to loop over their keys and values with for...of.
Syntax
for (const item of iterable) {
statements
}Example
Browser Support
The following information will show you the current browser support for the for...of statement. Hover over a browser icon to see the version that first introduced support for this statement.
Desktop





Tablets & Mobile





