Start of main content
Generator to array
JavaScript, Function, Array, Generator · Dec 31, 2020

Converts the output of a generator function to an array.
- Use the spread operator (
...
) to convert the output of the generator function to an array.
const generatorToArray = gen => [...gen];
const s = new Set([1, 2, 1, 3, 1, 4]);
generatorToArray(s.entries());
More like this

Master array manipulation in JavaScript with this ES6 snippet collection.
Collection · 203 snippets

Changes a function that accepts an array into a variadic function.
JavaScript, Function · Jun 13, 2021

Learn how to use JavaScript ES6 generators and iterators to iterate over ranges of numbers.
JavaScript, Function · Jun 12, 2021

Creates a generator, looping over the given array indefinitely.
JavaScript, Function · Oct 11, 2020