JavaScript - add array to Set

0 points
Created by:

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));

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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.

❤️💻 🙂