EN
JavaScript - convert Array to Set
0
points
In this article, we would like to show you how to convert Array to Set in JavaScript.
Quick solution:
// ONLINE-RUNNER:browser;
var array = [1, 2, 3];
var set = new Set(array);
Practical example
In this example, we use Set() constructor to convert Array to Set.
// ONLINE-RUNNER:browser;
const array = [1, 2, 2, 3, 3, 3];
const set = new Set(array); // constructor converts array to set
// print set items
console.log(...set); // 1, 2, 3