bhylu.com

Advertisements

JS Iterables

An iterable supplies a Symbol.iterator method. Arrays, strings, maps, and sets already follow this protocol.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const labels = new Set(["Open", "Full"]);
console.log([...labels]);
console.log([..."Hi"]);

What happens

Spread reads the Set values and the string characters.