Iterables and Iterators

An iterable is any object with a [Symbol.iterator]() method that returns an iterator: an object whose next() returns { value, done } records until done is true. Strings, arrays, typed arrays, Map, Set, arguments, generators and DOM collections such as NodeList are iterable; plain objects, WeakMap and WeakSet are not.

The iteration protocol: one iterator per loop, one next() call per value
The iteration protocol: one iterator per loop, one next() call per value

Prefer for...of over index loops: it works on every iterable and calls return() if you break. The asynchronous protocol, for await...of, is covered in Asynchronous Iteration.

Subsections