clear() 方法會從一個 Set 物件中移除其所有元素。

語法

mySet.clear();

回傳值

undefined.

範例

使用 clear 方法

var mySet = new Set();
mySet.add(1);
mySet.add('foo');

mySet.size;       // 2
mySet.has('foo'); // true

mySet.clear();

mySet.size;       // 0
mySet.has('bar')  // false

規範

規範 狀態
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Set.prototype.clear' in that specification.
Standard Initial definition.
ECMAScript Latest Draft (ECMA-262)
The definition of 'Set.prototype.clear' in that specification.
Draft  

瀏覽器相容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
clearChrome Full support 38Edge Full support 12Firefox Full support 19IE Full support 11Opera Full support 25Safari Full support 8WebView Android Full support 38Chrome Android Full support 38Edge Mobile Full support 12Firefox Android Full support 19Opera Android Full support 25Safari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12

Legend

Full support  
Full support

另見

文件標籤與貢獻者

此頁面的貢獻者: hmysjiang
最近更新: hmysjiang,