Languages
[Edit]
EN

JavaScript - add array to Set

0 points
Created by:
Aaron1
318

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]);
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join