concept

for...of Loop

The for...of loop is a JavaScript statement introduced in ES6 (ECMAScript 2015) that creates a loop iterating over iterable objects, such as arrays, strings, maps, sets, and other built-in iterables. It provides a concise and readable syntax for accessing each element directly, unlike traditional for loops that require index management. This loop automatically handles iteration protocols, making it ideal for working with collections in modern JavaScript.

Also known as: for of loop, for-of loop, ES6 for loop, for...of statement, for of
🧊Why learn for...of Loop?

Developers should use the for...of loop when they need to iterate over iterable objects without dealing with indices, as it simplifies code and reduces errors from manual index handling. It is particularly useful for arrays and strings where direct element access is needed, and for custom iterable objects implementing the Symbol.iterator protocol. Avoid using it for objects that are not iterable (like plain objects), where for...in or Object methods are more appropriate.

Compare for...of Loop

Learning Resources

Related Tools

Alternatives to for...of Loop