JavaScriptEasy
How do you convert a Set to an array in JavaScript?
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
To convert a Set to an array in JavaScript, you can use the Array.from() method or the spread operator. For example:
js
const mySet = new Set([1, 2, 3]);
const myArray = Array.from(mySet);
// OR const myArray = [...mySet];
console.log(myArray); // Output: [1, 2, 3]
