flâneur — a map of the web's best reading

Iteration protocols - JavaScript | MDN

developer.mozilla.org · 3,695 words · saved by 1 readers

Iteration protocols aren't new built-ins or syntax, but protocols. These protocols can be implemented by any object by following some conventions. There are two protocols: The iterable protocol and the iterator protocol. The iterable protocol allows JavaScript objects to define or customize their iteration behavior, such as what values are looped over in a for...of construct. Some built-in types are built-in iterables with a default iteration behavior, such as Array or Map, while other types (such as Object) are not. In order to be iterable, an object must implement the [Symbol.iterator]() method, meaning that the object (or one of the objects up its prototype chain) must have a property with a [Symbol.iterator] key which is available via constant Symbol.iterator: A zero-argument function that returns an object, conforming to the iterator protocol. Whenever an object needs to be iterated (such as at the beginning of a for...of loop), its [Symbol.iterator]() method is called with no arg

Iteration protocols - JavaScript | MDN Skip to main content Skip to search Iteration protocols Iteration protocols aren't new built-ins or syntax, but protocols . These protocols can be implemented by any object by following some conventions. There are two protocols: The iterable protocol and the iterator protocol . The iterable protocol The iterable protocol allows JavaScript objects to define or customize their iteration behavior, such as what values are looped over in a for...of construct. Some built-in types are built-in iterables with a default iteration behavior, such as Array or Map , w

Explore this link on the map →

saved by

related reading