試一試
const set = new Set();
set.add(42);
set.add(42);
set.add(13);
for (const item of set) {
console.log(item);
// Expected output: 42
// Expected output: 13
}
語法
js
add(value)
引數
返回值
Set 物件。
示例
使用 add()
js
const mySet = new Set();
mySet.add(1);
mySet.add(5).add("some text"); // chainable
console.log(mySet);
// Set [1, 5, "some text"]
規範
| 規範 |
|---|
| ECMAScript® 2026 語言規範 # sec-set.prototype.add |
瀏覽器相容性
載入中…