Add generatorToArray

This commit is contained in:
Chalarangelo
2020-12-31 13:22:18 +02:00
parent 7a31b979a0
commit 17c9cf690b

View File

@ -0,0 +1,17 @@
---
title: generatorToArray
tags: function,array,generator,beginner
---
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.
```js
const generatorToArray = gen => [...gen];
```
```js
const s = new Set([1, 2, 1, 3, 1, 4]);
generatorToArray(s.entries()); // [[ 1, 1 ], [ 2, 2 ], [ 3, 3 ], [ 4, 4 ]]
```