JS Coding Questions Logo
JS Coding Questions
#206💼 Interview💻 Code

List down the collection of methods available on WeakSet

Advertisement

728x90

Below are the list of methods available on WeakSet,

1. add(value): A new object is appended with the given value

2. delete(value): Deletes the value from the collection.

3. has(value): It returns true if the value is present in the collection, otherwise it returns false.

Let's see the functionality of all the above methods in an example,

javascript
1var weakSetObject = new WeakSet();
2
3var firstObject = {};
4
5var secondObject = {};
6// add(value)
7
8weakSetObject.add(firstObject);
9
10weakSetObject.add(secondObject);
11
12console.log(weakSetObject.has(firstObject)); //true
13
14weakSetObject.delete(secondObject);

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 36

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
206of476
List down the collection of methods available on WeakSet | JSCodingQuestions.com