Favorites

JavaScript for...of Statement

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
for...of
JavaScript IterationThis statement is supported by all modern browsers.
Updated 28th November 2026

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

const colors = ['red', 'green', 'blue'];
for (const color of colors) {
  console.log(color);
}

for (const [i, color] of colors.entries()) {
  console.log(i, color);
}

for (const char of 'hi!') console.log(char);

const prices = { tea: 3, cake: 5 };
for (const [item, price] of Object.entries(prices)) {
  console.log(item + ': $' + price);
}

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.

This statement is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee