JavaScript Code

How to convert a Set into Array in JavaScript?

Convert a Set into Array in JavaScript

Given a set of values, write a JavaScript program to convert the set into an array.


To convert given set of elements into an array in JavaScript, use the spread operator ... with the given set and enclose the expression in square brackets.


The above expression returns an array with the elements from the set.


1. Convert the set vowelSet into an array vowelArray.

const vowelSet = new Set(['a', 'e', 'i', 'o', 'u']);
const vowelArray = [...vowelSet];

copyright @2022