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
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-set-add-method
JavaScript Set add() Method - GeeksforGeeks
June 4, 2026 - 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.
🌐
Javatpoint
javatpoint.com › javascript-set-add-method
JavaScript Set add() Method - javatpoint
Syntax The clear() method is represented by the following syntax: setObj.clear() JavaScript example Here, we will understand clear() method through various examples. Example 1 Let's see a simple example of clear() method. <script> var set = new Set(); set.add("jQuery"); set.add("AngularJS"); set.add("Bootstrap"); document.writeln("Size before invoking...
🌐
W3Schools
w3schools.com › js › js_sets.asp
JavaScript Sets
You can create a JavaScript Set by: Passing an array to new Set() Create an empty set and use add() to add values · Pass an array to the new Set() constructor: // Create a Set const letters = new Set(["a","b","c"]); Try it Yourself » · Create ...
🌐
CoreUI
coreui.io › answers › how-to-add-to-a-set-in-javascript
How to add to a Set in JavaScript · CoreUI
November 6, 2025 - Use the add() method to insert new values into a Set while maintaining uniqueness automatically.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › javascript › javascript_set_add_method.htm
JavaScript - Set.add() Method
This method returns the Set object itself with the added values. In the following example, we are using the JavaScript Set.add() method to insert the numbers 5 and 10 to the "numberset" set −
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set
Set - JavaScript - MDN Web Docs
August 13, 2026 - Writeable Set-like objects additionally have the methods: clear(), delete(), and add().
🌐
Codecademy
codecademy.com › docs › javascript › sets › .add()
JavaScript | Sets | .add() | Codecademy
June 16, 2022 - Inserts a value into a Set (if it is unique) and returns the updated Set object.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set › values
Set.prototype.values() - JavaScript - MDN Web Docs - Mozilla
July 20, 2025 - const set = new Set(); set.add(42); set.add("forty two"); const iterator = set.values(); console.log(iterator.next().value); // Expected output: 42 console.log(iterator.next().value); // Expected output: "forty two"
🌐
Telerik
telerik.com › blogs › understanding-utilizing-javascript-set-object
Understanding and Utilizing the JavaScript Set Object
February 2, 2024 - By leveraging the Set's built-in methods for adding, checking and removing values, developers can simplify their code and reduce the complexity of handling distinct values. Moreover, the Set object ensures uniqueness, maintains insertion order and provides efficient value existence checks, which makes it a powerful tool in specific use cases. A Map object in JavaScript ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set › has
Set.prototype.has() - JavaScript - MDN Web Docs
September 22, 2025 - const mySet = new Set(); mySet.add("foo"); console.log(mySet.has("foo")); // true console.log(mySet.has("bar")); // false const set = new Set(); const obj = { key1: 1 }; set.add(obj); console.log(set.has(obj)); // true console.log(set.has({ key1: 1 })); // false, because they are different object references console.log(set.add({ key1: 1 })); // now set contains 2 entries
🌐
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 }
🌐
Medium
medium.com › @amirakhaled2027 › javascript-set-methods-95e94892703d
JavaScript Set Methods. A set in JavaScript is a collection of… | by Amira Khaled | Medium
June 11, 2024 - There are two primary ways to create sets in JavaScript: ... const mySet = new Set(); // Adding elements mySet.add("John"); mySet.add("Sherlock"); mySet.add("Watson"); mySet.add("Moriarty"); // Duplicate, ignored console.log(mySet); // Output: ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set › Set
Set() constructor - JavaScript - MDN Web Docs
September 13, 2025 - const mySet = new Set(); mySet.add(1); // Set [ 1 ] mySet.add(5); // Set [ 1, 5 ] mySet.add(5); // Set [ 1, 5 ] mySet.add("some text"); // Set [ 1, 5, 'some text' ] const o = { a: 1, b: 2 }; mySet.add(o);
🌐
Mozilla
developer.mozilla.org › en-US › blog › javascript-set-methods
New JavaScript Set methods - MDN Web Docs - Mozilla
June 24, 2024 - A set is similar to an Array, except that each value can only be stored once. For example, we can take a list of items, add them all to a set, and then inspect the results of the set. The list on the right is the contents of the <ol> list on the left, but converted to a set.