Files
30-seconds-of-code/snippets/generator-to-array.md
2023-04-28 22:29:23 +03:00

494 B

title, type, tags, author, cover, dateModified
title type tags author cover dateModified
Generator to array snippet
function
array
generator
chalarangelo messy-papers 2020-12-31T13:22:18+02:00

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()); // [[ 1, 1 ], [ 2, 2 ], [ 3, 3 ], [ 4, 4 ]]