How to convert array from set in javascript without using array.From?
Answers
Answered by
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)];
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
History,
6 months ago
Social Sciences,
11 months ago
Social Sciences,
11 months ago
Math,
1 year ago
Physics,
1 year ago