Categories
JavaScript Answers

How to convert a JavaScript iterable to an array?

Spread the love

To convert a JavaScript iterable to an array, we use the spread operator.

For instance, we write

const x = new Set([1, 2, 3, 4]);
const z = [...x];

to create a set with the Set constructor.

Then we convert the set to an array with the spread operator.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *