JavaScript weakSet has() Method
Last Updated :
22 Mar, 2023
JavaScript weakSet.has() method is used to return a boolean value indicating whether an object is present in a weakSet or not. The WeakSet object lets you store weakly held objects in a collection.
Syntax:
weakSet.has(value);
Parameters: This method accepts a single parameter value.
- value: This value is going to be checked whether it is present in the weakSet object or not.
Return Values: It returns a boolean value true if the element is present otherwise it returns false.
Below are examples of weakSet.has() method:
Example 1:
javascript
function gfg() {
const A = new WeakSet();
const object = {};
A.add(object);
console.log(A.has(object));
}
gfg();
|
Output: Here output is true because the object “object” is present in the WeakSet() object.
true
Example 2:
javascript
const A = new WeakSet();
const object1 = {};
A.add(object1);
console.log(A.has(object1));
|
Output: Here output is true because the object “object1” is present in the WeakSet() object.
true
Example 3:
javascript
const A = new WeakSet();
const object1 = {};
console.log(A.has(object1));
|
Output: Here the output is false because the object “object1” is not present in the WeakSet() object.
false
Supported Browsers:
- Google Chrome 36 and above
- Firefox 34 and above
- Apple Safari 9 and above
- Opera 23 and above
- Edge 12 and above
We have a complete list of Javascript weakSet methods, to check those please go through this JavaScript WeakSet Complete Reference article.
Share your thoughts in the comments
Please Login to comment...