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.