WeakSet add() JavaScript JS

The WeakSet add() method adds a new element to the end of a WeakSet object.

Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
weakSetObj.add(value)
weakSetObj.add(value)
weakSetObj.add(value)

Parameters:
value: It represents the element to add.

Returns:
Updated WeakSet object.

Example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script>
var hello = new WeakSet();
var obj={};
hello.add(obj);
document.writeln(hello.has(obj));
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script> var hello = new WeakSet(); var obj={}; hello.add(obj); document.writeln(hello.has(obj)); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script>  
var hello = new WeakSet();  
var obj={};    
hello.add(obj);    
document.writeln(hello.has(obj));   
</script>
</body>
</html>