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
🌐
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); const newSet = new Set([ ...existingSet, ...arr ]); console.log(newSet); // Set(5) { 1, 2, 5, 3, 4 } This works because ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-set-add-method
JavaScript Set add() Method | GeeksforGeeks
July 12, 2024 - The Set.add() method does not modify the set if the element with a specified value already exists in the set. ... Example 1: In this example, we have added two numbers 23 and 12 into the set.
🌐
W3Schools
w3schools.com › js › js_sets.asp
JavaScript Sets
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Certificate ... A JavaScript Set is a collection of unique values. Each value can only occur once in a Set. The values can be of any type, primitive values or objects. ... // Create a Set const letters = new Set(); // Add Values to the Set letters.add("a"); letters.add("b"); letters.add("c"); Try it Yourself »
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set › add
Set.prototype.add() - JavaScript - MDN Web Docs - Mozilla
const mySet = new Set(); mySet.add(1); mySet.add(5).add("some text"); // chainable console.log(mySet); // Set [1, 5, "some text"]
🌐
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.
🌐
Techie Delight
techiedelight.com › home › java › insert all array elements into a set in javascript
Insert all array elements into a set in JavaScript | Techie Delight
July 7, 2026 - Here’s an example: ... We can use the Array.forEach() function to execute a function for each element of the array and use the Set.add() function inside the function to add each element to the set.
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › javascript set add(): add values to a set
How to use JavaScript Set add() Method? [SOLVED]
June 17, 2026 - No. If the Set already contains the value, adding it again does not create a duplicate. Use chained add() calls, loop over an array, or create the Set from an array: new Set(array).
Find elsewhere
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › add-to-array
Add an Element to an Array in JavaScript - Mastering JS
June 18, 2021 - So the below loop is O(n^2). const ... 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' }...
🌐
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()):
🌐
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
🌐
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 - // Create an ArrayBuffer with a size in bytes const buffer = new ArrayBuffer(8); const uint8 = new Uint8Array(buffer); // Copy the values into the array starting at index 3 uint8.set([1, 2, 3], 3); console.log(uint8); // Expected output: Uint8Array [0, 0, 0, 1, 2, 3, 0, 0]
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-convert-array-to-set
How to Convert an Array to a Set in JavaScript | bobbyhadz
Set objects and arrays are iterable, so we are able to use the spread syntax (...) to unpack them into a new Set. You can also use a for...of loop to add an array of values to an existing Set.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set
Set - JavaScript - MDN Web Docs
August 13, 2026 - The Set object lets you store unique values of any type, whether primitive values or object references. Set objects are collections of values. A value in the set may only occur once; it is unique in the set's collection. 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).
🌐
freeCodeCamp
freecodecamp.org › news › set-and-map-in-javascript
How to Use Set and Map in JavaScript
February 10, 2023 - The example below shows a set created from an array of 4 elements. ... From the result, the code returns a set with 4 elements. Sets have several methods and a properties that you can use to retrieve, add, delete, check, and clear all the elements ...
🌐
Techie Delight
techiedelight.com › home › java › convert a set to an array in javascript
Convert a Set to an array in JavaScript | Techie Delight
July 7, 2026 - Another solution is to individually add each element in the set to the array. This can be easily done using the forEach() function. This function iterates over the elements of an iterable object, such as a set, and pushes them to a new array. Here’s an example of this approach:
🌐
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 - Example - 1: Converting a set to array by using forEach() method. ... Explanation: The function that we provided the Set. Each value in the Set triggers the forEach method to be called. We only push the value into the array after each iteration. ... In this article, we have discussed various ...
🌐
Medium
habtesoft.medium.com › add-elements-to-an-array-in-javascript-a9cc6cd9469f
Add elements to an array in JavaScript | by habtesoft | Medium
October 18, 2024 - The splice() method can also be used to add elements to an array in JavaScript. The splice() method adds or removes elements from an array at a specified index. Here’s an example of how to add elements to an array using splice():
🌐
Mimo
mimo.org › tutorials › javascript › how-to-add-to-an-array-in-javascript
How to Add to an Array in JavaScript
Use unshift() to add items to the start of an array. ... It shifts existing elements to the right. Use splice() when you need to insert at a certain index. ... First argument: index to start. Second argument: how many items to remove. Remaining arguments: items to insert.