JavaScript Iterables


Iterable objects are iterables (like Arrays). Accessing iterables requires just short, effective code. Using for..of loops, iterables may be repeated over and again.


lterables over a string

A for..of loop may be used to repeatedly traverse through a string's components. Because a string is an iterable object in JavaScript, we can iterate through its characters using a for...of loop.

Example

Preview

lterables over an array

An Array's items can be iterated through using a for..of loop. Arrays are iterable objects in JavaScript, which means we can traverse through their elements using a for...of loop or other iterable methods.

Example

Preview

lterables over a set

A for..of loop may be used to repeatedly traverse through a Set's components. Set objects are iterable in JavaScript, allowing us to traverse through their values using a for...of loop or other iterable techniques.

Example

Preview

lterables over a map

A for..of loop may be used to repeatedly traverse through a map's components. Because Map objects in JavaScript are iterable, we may traverse over their key-value pairs using a for...of loop or other iterable methods.

Example

Preview