add()
會在一個 Set
物件的尾端加上一個指定 value
的新元素。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
語法
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"]
規範
規範 | 狀態 | 註 |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Set.prototype.add' in that specification. |
Standard | Initial definition. |
ECMAScript (ECMA-262) The definition of 'Set.prototype.add' in that specification. |
Living Standard |
瀏覽器相容性
BCD tables only load in the browser