Set to Array in JS or JavaScript Last Updated : 10 May, 2025 Comments Improve Suggest changes Like Article Like Report 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:1. Using Spread OperatorThe JavaScript Spread Operator can be used to destructure the elements of the array and then assign them to a new variable in the form of an array. JavaScript let s = new Set(['GFG', 'JS']); let a = [...s]; console.log(a); Output[ 'GFG', 'JS' ] 2. 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. JavaScript 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 ] 3. Using forEach() MethodThe 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. JavaScript let s = new Set(['GFG', 'JS']); let a = []; let fun = function (val1) { a.push(val1); }; s.forEach(fun); console.log(a); Output[ 'GFG', 'JS' ] 4. Using Lodash _.toArray() MethodLodash 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. JavaScript // 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' ]));)); Comment More infoAdvertise with us Next Article Set to Array in JS or JavaScript K kartikgoel1999 Follow Improve Article Tags : JavaScript Web Technologies javascript-array JavaScript-DSA JavaScript-Questions JavaScript-Set +2 More Similar Reads Set vs Array in JavaScript In JavaScript, Set and Array are common data structures used to store collections of data. These data structures are different because of their unique features. Let us look at the implementation of both of these data structures. JavaScript SetSets are used to store collections of unique value withou 2 min read JavaScript- Add an Object to JS Array In JavaScript, arrays are used to store multiple values in a single variable, and objects are collections of properties and values. Sometimes, we may need to add an object to an array to manage data more effectively. These are the following ways to add an object to a JS array: Using JavaScript Array 4 min read Types of Arrays in JavaScript A JavaScript array is a collection of multiple values at different memory blocks but with the same name. The values stored in an array can be accessed by specifying the indexes inside the square brackets starting from 0 and going to the array length - 1([0]...[n-1]). A JavaScript array can be classi 3 min read JavaScript | JSON Arrays The JSON Arrays is similar to JavaScript Arrays. Syntax of Arrays in JSON Objects: // JSON Arrays Syntax { "name":"Peter parker", "heroName": "Spiderman", "friends" : ["Deadpool", "Hulk", "Wolverine"] } Accessing Array Values: The Array values can be accessed using the index of each element in an Ar 2 min read JavaScript - Convert String to Array Strings in JavaScript are immutable (cannot be changed directly). However, arrays are mutable, allowing you to perform operations such as adding, removing, or modifying elements. Converting a string to an array makes it easier to:Access individual characters or substrings.Perform array operations su 5 min read JavaScript Array fill() Method The fill() method in JavaScript is used to fill all the elements of an array from a start index to an end index with a static value. It mutates the original array and returns the modified array. Syntax: arr.fill(value, start, end)Parameters: This method accepts three parameters as described below: P 3 min read JavaScript Array fill() Method The JavaScript Array fill() Method fills a given range of array elements with the given value. This method is used to manipulate the existing array according to our needs.Syntax:arr.fill(value,start,end)Parameters:Value: Value to be filled.Start: Start index (included) and its default value is 0.End 3 min read How to Get the Size of an Array in JavaScript To get the size (or length) of an array in JavaScript, we can use array.length property. The size of array refers to the number of elements present in that array. Syntaxconst a = [ 10, 20, 30, 40, 50 ] let s = a.length; // s => 5 The JavaScript Array Length returns an unsigned integer value that 2 min read Convert Array to String in JavaScript In JavaScript, converting an array to a string involves combining its elements into a single text output, often separated by a specified delimiter. This is useful for displaying array contents in a readable format or when storing data as a single string. The process can be customized to use differen 7 min read Javascript Array at() Method The JavaScript Array at() method takes an integer value (index) as a parameter and returns the element of that index. It allows positive and negative integers. For the negative integer, it counts back from the last element in the array.Syntax:at(index);Parameter: This method accepts one parameter th 3 min read Like