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:
xxxxxxxxxx
1
var array = [1, 2, 3];
2
var set = new Set(array);
In this example, we use Set()
constructor to convert Array
to Set
.
xxxxxxxxxx
1
const array = [1, 2, 2, 3, 3, 3];
2
const set = new Set(array); // constructor converts array to set
3
4
// print set items
5
console.log(set); // 1, 2, 3