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 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' }
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
How to give an object property multiple values in js
You need to define each level. You can't do this: let obj = {}; obj.bla.a = 3; It will tell you that obj.bla is not defined. Rather, you have to define the bla property first, and then you can add sub-properties to it. Like so: let obj = {}; obj.bla = {}; obj.bla.a = 3; Good luck learning js, its been fun last couple of months for me! More on reddit.com
Setinterval() going crazy. Can't figure it out!
Move your line 15,
var tweetcounter;
Out of the function. clearInterval runs against undefined, then you assign it, then it goes out of scope.
Or do what u/uazaa says and make it a setTimeout instead.
More on reddit.comHelp with multiple lined innerHTML assignment
and i want to continue on line 2 </p> was supposed to be on the next line
More on reddit.comHow to append multiple classes to an element? JavaScript DOM
Use classList instead of setAttribute. setAttribute should be avoided for setting classes, as it will overwrite whatever is already set, making adding classes overly complicated. Also, avoid making multiple appends to your DOM whenever possible. Build up the section element, appending all of its child elements, then append the section element to your "workspace." Also also, the code you have written does not match the HTML. You are appending the city div outside the section, instead of nested in an H2 element. More on reddit.com
04:55
Store Multiple Values in one Variable using JavaScript Arrays - ...
05:11
Sets in Javascript (Set Object) - YouTube
07:38
5 Ways to Add Items to Arrays in JavaScript - YouTube
21:19
How to appendChild multiple elements in JavaScript | JavaScript ...
04:39
Get And Set Multiple Elements Attributes - YouTube
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 - They both have the same type and name, but because they are two different objects in memory, the Set treats them as two unique dragons. This is because JavaScript objects are compared by reference, not by their content (value). Now, what happens if someone tries to add the same exact dragon twice?
GeeksforGeeks
geeksforgeeks.org โบ javascript โบ javascript-insert-multiple-elements-in-js-array
JavaScript - Insert Multiple Elements in JS Array - GeeksforGeeks
July 23, 2025 - This method creates a new array to insert elements. The JavaScript spread syntax (...) can be used to add multiple elements in the JS array.
freeCodeCamp
freecodecamp.org โบ news โบ how-to-use-javascript-collections-map-and-set
How to Use JavaScript Collections โ Map and Set
October 5, 2020 - Please note, if you use the same key to add a value to a Map multiple times, it'll always replace the previous value: // Add a different writer map.set('writer', 'Someone else!'); ... Map keys can be of any type, a primitive, or an object. This is one of the major differences between Map and regular JavaScript objects where the key can only be a string:
ZetCode
zetcode.com โบ js-array โบ set
JavaScript set() - working with Sets in JS
We add object references to a Set. Even though obj1 and obj2 have identical properties, they are different objects in memory. Adding the same object reference multiple times only stores it once.
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 - The set() method of TypedArray instances stores multiple values in the typed array, reading input values from a specified array.
GeeksforGeeks
geeksforgeeks.org โบ javascript-insert-multiple-elements-in-js-array
JavaScript โ Insert Multiple Elements in JS Array | GeeksforGeeks
November 15, 2024 - We can insert an item into Array at a specific index using the JavaScript Array splice method. This method removes the elements from the mentioned index and add items at that specific position.1.
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);
YouTube
youtube.com โบ code 2020
JavaScript tips โ Add multiple values to an array using Array.push - YouTube
Add multiple values to an array in JavaScript by calling array.push with a list of arguments. This will append the list of arguments to the end of the array ...
Published: October 9, 2022
Views: 3K