A set can be converted to an array in JavaScript by the following way-
- By using Array.from() method:
This method returns a new Array from an array like object or iterable objects like Map, Set, etc.
SyntaxArray.from(arrayLike object);
Example-1
<!DOCTYPE html><html><head><title>Convert Set to Array</title></head><body><center><h1 style="color:green">GeeksforGeeks</h1><script>const set =newSet(['welcome','to','GFG']);Array.from(set);document.write(Array.from(set));</script></center></body></html>chevron_rightfilter_noneOutput

- Using spread operator:
Using of spread operator can also help us convert Set to array.
Syntaxvar variablename = [...value];
Example-2:
<!DOCTYPE html><html><head><title>Convert Set to Array</title></head><body><center><h1 style="color:green">GeeksforGeeks</h1><script>const set =newSet(['GFG','JS']);const array = [...set];document.write(array);</script></center></body></html>chevron_rightfilter_noneOutput

- Using forEach:
Example-3:<!DOCTYPE html><html><head><title>Convert Set to Array</title></head><body><center><h1 style="color:green">GeeksforGeeks</h1><script>vargfgSet =newSet();vargfgArray = [];gfgSet.add("Geeks");gfgSet.add("for");// duplicate itemgfgSet.add("Geeks");varsomeFunction =function(val1, val2, setItself) {gfgArray.push(val1);};gfgSet.forEach(someFunction);document.write("Array: "+ gfgArray);</script></center></body></html>chevron_rightfilter_noneOutput

Supported Browsers:
- Google Chrome
- Firefox
- Edge
- Opera
- Apple Safari
Recommended Posts:
- How to Convert Array to Set in JavaScript?
- How to convert Integer array to String array using JavaScript ?
- How to convert Object's array to an array using JavaScript ?
- Convert an Array to an Object in JavaScript
- JavaScript | Convert an array to JSON
- Convert comma separated string to array using JavaScript
- How to convert Map keys to an array in JavaScript ?
- How to convert PHP array to JavaScript or JSON ?
- How to convert arguments object into an array in JavaScript ?
- How to convert an Object {} to an Array [] of key-value pairs in JavaScript?
- How to convert a DOM nodelist to an array using JavaScript ?
- How to convert JSON string to array of JSON objects using JavaScript ?
- Fastest way to convert JavaScript NodeList to Array
- JavaScript | Convert a string to boolean
- Convert a string to an integer in JavaScript
- How to convert a float number to the whole number in JavaScript?
- How to convert a JavaScript date to UTC?
- Convert string to title case in JavaScript
- Convert string into date using JavaScript
- How to convert an object to string using JavaScript?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


