Set to Array in JS or JavaScript
This article will show you how to convert a Set to an Array in JavaScript. A set can be converted to an array in JavaScript in the following ways:
Using Spread Operator
The JavaScript Spread Operator can be used to destructure the elements of the array and then assign them to the new variable in the form of an array.
let s = new Set(['GFG', 'JS']);
let a = [...s];
console.log(a);
Output
[ 'GFG', 'JS' ]
Using Array.from()
JavaScript Array.from() Method returns a new Array from an array, object or other iterable objects like Map, Set, etc. It takes the set as parameter and converts it to an array.
const s = new Set([1, 1, 2, 3, 4, 4, 5, 6, 5]);
let a = Array.from(s);
console.log(a);
Output
[ 1, 2, 3, 4, 5, 6 ]

Using forEach() Method
The arr.forEach() method calls the provided function once for each element of the set where they are pushed to an array using the push() method.
let s = new Set(['GFG', 'JS']);
let a = [];
let fun = function (val1) {
a.push(val1);
};
s.forEach(fun);
console.log(a);
Output
[ 'GFG', 'JS' ]
Using Lodash _.toArray() Method
Lodash is an JavaScript library that allows us to use the _.toArray() method which accepets a value and convert it to an array.
NOTE: To use this approach, you need to install the lodash library into your local system using the npm i lodash command.
Syntax:
const arrayName = _.toArray(setName);
Example: The below code implements the _.toArray() method of the lodash library to convert a set into an array.
// Requiring the lodash library
const _ = require("lodash");
let s = new Set(['welcome', 'to', 'GFG']);
// Use of _.toArray() method
console.log(_.toArray(s));
Output:
Set Elements: Set(3) { 'welcome', 'to', 'GFG' }
Array Elements: [ 'welcome', 'to', 'GFG' ]));));