OneCompiler

[JavaScript] How to convert an array into a set?

In Javascript, how to convert a given array of elements into a Set?

1 Answer

4 years ago by

You can create set from an array by passing the array to the Set constructor

let colors = ["red", "green", "blue", "orange", "maroon", "blue"];
let colorSet = new Set(colors);
console.log(colorSet);

Run here https://onecompiler.com/javascript/3xn77vr59

4 years ago by Meera