| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Set/add | [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 20157.
add() Set value
const set1 = new Set();
set1.add(42);
set1.add(42);
set1.add(13);
for (const item of set1) {
console.log(item);
// Expected output: 42
// Expected output: 13
}
mySet.add(value);
value Set
Set
add var mySet = new Set();
mySet.add(1);
mySet.add(5).add("some text"); // chainable
console.log(mySet);
// Set [1, 5, "some text"]
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-set.prototype.add |
This page was last modified on 2025714 by MDN contributors.
Your 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 |