The has method of the JavaScript WeakSet determines if a specific object exists within the WeakSet instance. It will return true if the given object is found, and false if it is not present.
Syntax
The syntax for the has method is illustrated as follows:
Example
weakSetObj.has(value)
Parameter
value - It represents the object to be searched.
Return
A Boolean value.
JavaScript WeakSet has method example
Let us examine an illustration to ascertain if the WeakSet object includes the designated object.
Example
<script>
var ws = new WeakSet();
var obj1={};
var obj2={};
ws.add(obj1);
document.writeln(ws.has(obj1)+"<br>");
document.writeln(ws.has(obj2)+"<br>");
document.writeln(ws.has());
</script>
Output:
Output
true
false
false