Categories
JavaScript Answers

How to convert JavaScript iterable to array?

Spread the love

Sometimes, we want to convert JavaScript iterable to array.

In this article, we’ll look at how to convert JavaScript iterable to array.

How to convert JavaScript iterable to array?

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

For instance, we write

const map = new Map([
  [1, "one"],
  [2, "two"],
]);

const newArr = [...map];

to convert the map to the newArr array.

newArr is an array with arrays of keys and values in the map.

Conclusion

To convert JavaScript iterable to array, we can use 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 *