Baseline Widely available
The has()
method of WeakSet
instances returns a boolean indicating whether an object exists in this WeakSet
or not.
const weakset1 = new WeakSet();
const object1 = {};
const object2 = {};
weakset1.add(object1);
console.log(weakset1.has(object1));
// Expected output: true
console.log(weakset1.has(object2));
// Expected output: false
Syntax Parameters
value
The value to test for presence in the WeakSet
.
Returns true
if an element with the specified value exists in the WeakSet
object; otherwise false
. Always returns false
if value
is not an object or a non-registered symbol.
has()
method
const ws = new WeakSet();
const obj = {};
ws.add(window);
ws.has(window); // returns true
ws.has(obj); // returns false
// Storing a non-registered symbol
const sym = Symbol("foo");
ws.add(sym);
ws.add(Symbol.iterator);
Specifications Browser compatibility See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4