Files
30-seconds-of-code/snippets/generatorToArray.md
2022-12-04 22:20:49 +02:00

530 B

title, tags, author, cover, firstSeen, lastUpdated
title tags author cover firstSeen lastUpdated
Generator to array function,array,generator chalarangelo blog_images/messy-papers.jpg 2020-12-31T13:22:18+02:00 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 ]]