Set.prototype.add()

add() 會在一個 Set 物件的尾端加上一個指定 value 的新元素。

語法

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 Latest Draft (ECMA-262)
The definition of 'Set.prototype.add' in that specification.
Draft  

瀏覽器相容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
addChrome Full support 38Edge Full support 12Firefox Full support 13IE Partial support 11
Notes
Partial support 11
Notes
Notes Returns 'undefined' instead of the 'Set' object.
Opera Full support 25Safari Full support 8WebView Android Full support 38Chrome Android Full support 38Firefox Android Full support 14Opera Android Full support 25Safari iOS Full support 8Samsung Internet Android Full support 3.0nodejs Full support Yes

Legend

Full support  
Full support
Partial support  
Partial support
See implementation notes.
See implementation notes.

另見