Obsolete
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

The clear() method used to remove all elements from a WeakMap object, but is no longer part of ECMAScript and its implementations.

Syntax

wm.clear();

Examples

Using the clear method

var wm = new WeakMap();
var obj = {};

wm.set(obj, 'foo');
wm.set(window, 'bar');

wm.has(obj); // true
wm.has(window); // true

wm.clear();

wm.has(obj)  // false
wm.has(window)  // false

Specifications

Not part of any current specification or draft. This method was part of the ECMAScript 6 draft specification until revision 28 (version of October 14, 2014), but has been removed in later versions of the draft. It is not part of the final standard.

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung InternetNode.js
Basic support
DeprecatedNon-standard
Chrome No support 36 — 43Edge No support NoFirefox No support 20 — 46IE Full support 11Opera No support 25 — 30Safari No support 8 — 9WebView Android No support 37 — 43Chrome Android No support 36 — 43Edge Mobile No support NoFirefox Android No support 20 — 46Opera Android No support 25 — 30Safari iOS No support 8 — 9Samsung Internet Android Full support Yesnodejs Full support Yes

Legend

Full support  
Full support
No support  
No support
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.

See also

Document Tags and Contributors

Contributors to this page: teoli, m_gol, fscholz, nmve, claudepache, realityking
Last updated by: teoli,