Computer Science, asked by bunty788, 11 months ago

How to convert array from set in javascript without using array.From?

Answers

Answered by Anonymous
0
Indeed, there are several ways to convert a Set to an Array:

using Array.from

let array = Array.from(mySet);

Simply spreading the Set out in an array

let array = [...mySet];

The old fashion way, iterating and pushing to a new array (Sets do have forEach)

let array = []; mySet.forEach(v => array.push(v));

Using a fancier for...of loop (this doesn't seem to work in Chrome anymore)

let array = [v for (v of mySet)];
Similar questions