JavaScript Code

How to convert a Set into Array in JavaScript?

Problem Statement

given a set, write a JavaScript program to convert a set into 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