EN
JavaScript - add array to Set
0
points
In this article, we would like to show you how to add array to set in JavaScript.
Practical example
In this example, we use forEach()
method with an arrow function to add items from array to the set.
// ONLINE-RUNNER:browser;
const myArray = [1, 2, 3];
const mySet = new Set();
myArray.forEach(item => mySet.add(item));
console.log([...mySet]);