| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/Set | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since July 2015.
The Set() constructor creates Set objects.
const set = new Set([1, 2, 3, 4, 5]);
console.log(set.has(1));
// Expected output: true
console.log(set.has(5));
// Expected output: true
console.log(set.has(6));
// Expected output: false
new Set()
new Set(iterable)
iterable OptionalIf an iterable object (such as an array) 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 or undefined, 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 2027 LanguageSpecification # sec-set-constructor |
This page was last modified on Sep 13, 2025 by MDN contributors.
SetObject/FunctionYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |