The Set()
constructor creates Set
objects.
The Set()
constructor creates Set
objects.
iterable
Optional
If an iterable object is passed, all of its elements will be added to the new Set
.
If you don't specify this parameter, or its value is null
, the new Set
is empty.
A new Set
object.
Set
objectconst 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);
Specification |
---|
ECMAScript Language Specification # sec-set-constructor |
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | Deno | Node.js | ||
Set |
38 | 12 | 13 | 25 | 8 | 38 | 14 | 25 | 8 | 3.0 | 38 | 1.0 | 0.12.0 | |
iterable_allowed |
38 | 12 | 13 | 25 | 9 | 38 | 14 | 25 | 9 | 3.0 | 38 | 1.0 | 0.12.0 | |
new_required |
38 | 12 | 42 | 25 | 9 | 38 | 42 | 25 | 9 | 3.0 | 38 | 1.0 | 0.12.0 | |
null_allowed |
38 | 12 | 37 | 25 | 9 | 38 | 37 | 25 | 9 | 3.0 | 38 | 1.0 | 0.12.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/Set