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 OverflowMDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set › add
Set.prototype.add() - JavaScript | MDN
September 22, 2025 - The add() method of Set instances inserts the specified value into this set, if it is not already present.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set
Set - JavaScript | MDN
August 13, 2026 - Writeable Set-like objects additionally have the methods: clear(), delete(), and add().
14:58
#3. Set in JavaScript - Easy Explanation #javascript - YouTube
06:57
JS Sets - Javascript Programming 24 - YouTube
07:06
JavaScript Set Explained - YouTube
07:22
JavaScript Set Add() Method - YouTube
02:20
JavaScript Basics - How to use Object Sets - YouTube
15:23
Sets - Javascript In Depth - YouTube
Top answer 1 of 12
264
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)
2 of 12
137
Here's a functional way, returning a new set:
const set = new Set(['a', 'b', 'c'])
const arr = ['d', 'e', 'f']
const extendedSet = new Set([ ...set, ...arr ])
// Set { 'a', 'b', 'c', 'd', 'e', 'f' }
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set › has
Set.prototype.has() - JavaScript | MDN
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
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 › size
Set.prototype.size - JavaScript | MDN
July 20, 2025 - const mySet = new Set(); mySet.add(1); mySet.add(5); mySet.add("some text"); console.log(mySet.size); // 3
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set › values
Set.prototype.values() - JavaScript | MDN
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"
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 - Even if this second dragon looks exactly like the first — same scales, same fire breath — I can’t say they’re the same just by looking. I have to see if they have the same magical essence. In the JavaScript world, when you add an object (like my dragons) to a Set, the Set doesn’t compare their appearance; it checks if they’re exactly the same object in memory — the same essence.
Illinois State Library
ilsos.gov › departments › drivers › mobile-id › apple-wallet.html
ID in Apple Wallet
To add your ID to your iPhone and any paired Apple Watch, open Apple Wallet and tap the plus sign (+) at the top-right corner of the screen. Select Driver's License or State ID, then follow the onscreen instructions to start the setup process.
Microsoft Learn
learn.microsoft.com › en-us › office › dev › add-ins › develop › understand-the-javascript-api-for-office
Understand the Office JavaScript API - Office Add-ins | Microsoft Learn
For example, you can use the Excel JavaScript APIs to access worksheets, ranges, tables, charts, and more. Application-specific APIs are currently available for the following Office applications. ... This API model uses promises and allows you to specify multiple operations in each request you send to the Office application. Batching operations in this manner can significantly improve add-in performance in Office applications on the web.
YouTube
youtube.com › watch
Sets in Javascript (Set Object) - YouTube
Similar to Arrays, a Set can be used to store a sequence of values in Javascript. However, a Set can only store unique values, meaning we cannot store duplic...
Published: December 24, 2017
Firebase
firebase.google.com › documentation › firebase for web platforms › add firebase to your javascript project
Add Firebase to your JavaScript project | Firebase for web platforms
A guide to adding Firebase to your JavaScript project, including how to create a Firebase project, register your app, and initialize the Firebase SDK.
Google Workspace
workspace.google.com › marketplace › app › email_notifications_for_google_forms › 984866591130
Email Notifications for Google Forms™ - Google Workspace Marketplace
I've had the app loaded for about 1 year. I set up the app with a form I use and it has worked with the initial email addresses. I have never been able to open the app to add more emails. The tutorial video says to open the add-on in my form. However when I open the "puzzle piece" in my form, the app is listed, but I'm not given the option to open it.
Chrome for Developers
developer.chrome.com › docs › chrome devtools › view, add, edit, and delete cookies
View, add, edit, and delete cookies | Chrome DevTools | Chrome for Developers
December 5, 2023 - HTTP Cookies are mainly used to manage user sessions, store user personalization preferences, and track user behavior. They are also the cause of all of those annoying "this page uses cookies" consent forms that you see across the web. This guide teaches you how to view, add, edit, and delete a page's cookies with Chrome DevTools.
Mozilla
developer.mozilla.org › en-US › blog › javascript-set-methods
New JavaScript Set methods | MDN Blog
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.