The has()
method returns a boolean indicating whether an
object exists in a WeakSet
or not.
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.
Syntax
ws.has(value);
Parameters
value
- Required. The object to test for presence in the
WeakSet
.
Return value
- Boolean
- Returns
true
if an element with the specified value exists in theWeakSet
object; otherwisefalse
.
Examples
Using the has method
var ws = new WeakSet();
var obj = {};
ws.add(window);
mySet.has(window); // returns true
mySet.has(obj); // returns false
Specifications
Browser compatibility
BCD tables only load in the browser