While Set API is still very minimalistic, you can use Array.prototype.forEach and shorten your code a bit:

array.forEach(item => mySet.add(item))

// alternative, without anonymous arrow function
array.forEach(mySet.add, mySet)
Answer from amankkg on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set
Set - JavaScript - MDN Web Docs
August 13, 2026 - You can iterate through the elements of a set in insertion order. The insertion order corresponds to the order in which each element was inserted into the set by the add() method successfully (that is, there wasn't an identical element already in the set when add() was called).
🌐
Designcise
designcise.com › web › tutorial › how-to-add-array-values-to-an-existing-javascript-set
How to Add Array Values to an Existing JavaScript Set? - Designcise
September 27, 2021 - // ES6+ const arr = [1, 2, 3, 3, 4]; const existingSet = new Set(); existingSet.add(1); existingSet.add(2); existingSet.add(5); arr.forEach((item) => existingSet.add(item)); console.log(existingSet); // Set(5) { 1, 2, 5, 3, 4 } You can of course, use any other loop to iterate over the array as you want.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-set-add-method
JavaScript Set add() Method | GeeksforGeeks
July 12, 2024 - The Set.add() method in JavaScript is used to append an element with a specified value in a set. It modifies the existing set by appending the new element but does not return a new set.
🌐
W3Schools
w3schools.com › js › js_sets.asp
JavaScript Sets
The values can be of any type, primitive values or objects. Share Link Copied · You can create a JavaScript Set by: Passing an array to new Set() Create an empty set and use add() to add values ·
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › add-to-array
Add an Element to an Array in JavaScript - Mastering JS
June 18, 2021 - Using includes() works, but can cause performance issues because includes() scans through the entire array every time you call it. So the below loop is O(n^2). const arrWithoutDuplicates = []; for (let i = 0; i < arr.length; ++i) { if (arrWithoutDuplicates.includes(arr[i])) { continue; } arrWithoutDuplicates.push(arr[i]); } Instead, we recommend using a JavaScript set to represent a collection of objects where every element should be unique. const set = new Set(['a', 'b', 'c']); set.add('a'); set; // Set(3) { 'a', 'b', 'c' } set.add('d'); set; // Set(4) { 'a', 'b', 'c', 'd' }
🌐
Mimo
mimo.org › tutorials › javascript › how-to-add-to-an-array-in-javascript
How to Add to an Array in JavaScript
Learn how to add to an array in JavaScript using push(), unshift(), splice(), and spread for mutable or immutable updates.
Find elsewhere
🌐
Medium
medium.com › @conboys111 › what-happens-when-you-add-objects-or-arrays-to-a-javascript-set-b9f15dbbc5e0
What Happens When You Add Objects or Arrays to a JavaScript Set? | by myHotTake | Medium
November 11, 2024 - Here, since the same object (dragon1) is being added twice, the Set recognizes it and rejects the duplicate. It’s like someone trying to sneak the exact same dragon back into the shelter—nope, I already know that dragon! Arrays in JavaScript behave similarly to objects in Sets.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-convert-set-to-array-in-javascript
Set to Array in JS or JavaScript | GeeksforGeeks
May 10, 2025 - Strings in JavaScript are immutable (cannot be changed directly). However, arrays are mutable, allowing you to perform operations such as adding, removing, or modifying elements.
🌐
CoreUI
coreui.io › answers › how-to-add-to-a-set-in-javascript
How to add to a Set in JavaScript · CoreUI
November 6, 2025 - Learn how to add values to JavaScript Set objects using the add method for building unique collections.
🌐
freeCodeCamp
freecodecamp.org › news › set-and-map-in-javascript
How to Use Set and Map in JavaScript
February 10, 2023 - And it returns a value, which was an array of a single object that contains a date and price. ... We added the key-value pair kamal and lawal to an empty map with the set method. The set method is where you set a key-value pair. The key has to be the first option and the value has to be the last.
🌐
JSchallenger
jschallenger.com › javascript-practice › javascript-sets › add-multiple-elements-to-javascript-set
Add multiple elements to Set | JSchallenger
JSchallenger. Write a function that takes a Set and an array as arguments. If not already existing, add each element in the array to the Set. Return the modified Set
🌐
DEV Community
dev.to › clairecodes › how-to-create-an-array-of-unique-values-in-javascript-using-sets-5dg6
How to create an array of unique values in JavaScript using Sets - DEV Community
May 8, 2018 - There are two ways to add values to a Set. Firstly by using the add method as above. Secondly by passing an array to the constructor (new Set()):
🌐
freeCodeCamp
freecodecamp.org › news › how-to-insert-an-element-into-an-array-in-javascript
Push into an Array in JavaScript – How to Insert an Element into an Array in JS
November 7, 2024 - If we want to add to the array, we set the second argument to zero (0), instructing the splice() method not to delete any array elements.
🌐
Web Dev Simplified
blog.webdevsimplified.com › 2021-01 › javascript-sets
Start Using JavaScript Sets Now - Web Dev Simplified Blog
Once you have a Set you will most likely need a way to add items to that Set. This is a simple as using the add method and passing the item to add. This works just like push does for arrays and adds the item to the end of the list, but the add ...
🌐
Scaler
scaler.com › home › topics › how to convert set to array in javascript
How to Convert Set to Array in JavaScript - Scaler Topics
May 4, 2023 - JavaScript offers several ways to convert a set to an array but forEach() method is more efficient because every element in the array is given a separate execution of the provided function by the forEach method.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › TypedArray › set
TypedArray.prototype.set() - JavaScript - MDN Web Docs
July 10, 2025 - const buffer = new ArrayBuffer(8); const uint8 = new Uint8Array(buffer); uint8.set([1, 2, 3], 3); console.log(uint8); // Uint8Array [ 0, 0, 0, 1, 2, 3, 0, 0 ] Polyfill of TypedArray.prototype.set in core-js · JavaScript typed arrays guide · TypedArray · ArrayBuffer ·
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-convert-array-to-set-in-javascript
How to Convert Array to Set in JavaScript? | GeeksforGeeks
October 25, 2024 - Converting Array to Set means transforming the array elements into a Set object. The Set constructor in JavaScript directly converts an array into a Set. This process automatically filters out duplicate elements, creating a collection of unique ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › set-vs-array-in-javascript
Set vs Array in JavaScript - GeeksforGeeks
August 5, 2025 - let sample = new Set(); sample.add("Hello"); sample.add(1) sample.add("Bye") sample.add("@"); for (let item of sample) { console.log(item); } ... The array is a data structure that is used to store data in a sequential manner of the same type.