JavaScript | weakSet.delete() with Example
The weakSet.delete() is an inbuilt function in JavaScript which is used to delete an specific element from a weakSet object.
Syntax:
weakSet.delete(A);
Parameters: It accepts a parameter “A” which is a value going to be deleted from the weakset object.
Return Values: It returns true if the element has been removed successfully from the weakset object and false if the element has not been removed successfully or the element is not found in the weakset.
Code #1:
<script> // Constructing weakSet() object const A = new WeakSet(); // Creating a new element const B = {}; // Adding the element to the weakset object A.add(B); // Testing whether the element has been // set into the weakset object or not document.write(A.has(B) +"<br>"); // Deleting B form the weakSet() object A.delete(B); // Testing whether the element "B" has been deleted or not document.write(A.has(B) +"<br>"); </script> |
Output:
true false
Here output is true at first it means that element “B” has been set into the weakSet object successfully and after it false which says that the element “B” has been deleted successfully from the weakSet object.
Recommended Posts:
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Understanding Code Structure in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Operators in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript Course | Variables in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript Course | Objects in JavaScript
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- Map.get( ) In JavaScript
- JavaScript | Let
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



