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:
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:
// Constructing a weakSet() object
const A = new WeakSet();
// Constructing new objects
const object1 = {};
// Adding the new object to the weakSet
A.add(object1);
// Checking whether the new object is present
// in the weakSet or not
console.log(A.has(object1));
Output: Here output is true because the object "object1" is present in the WeakSet() object.
true
Example 3:
// Constructing a weakSet() object
const A = new WeakSet();
// Constructing new objects
const object1 = {};
// Checking whether the new object is present
// in the weakSet or not
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.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
