0 votes
in JavaScript by
List down the collection of methods available on WeakSet?

1 Answer

0 votes
by

Below are the list of methods available on WeakSet,

  1. add(value): A new object is appended with the given value to the weakset
  2. delete(value): Deletes the value from the WeakSet collection.
  3. has(value): It returns true if the value is present in the WeakSet Collection, otherwise it returns false.

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

var weakSetObject = new WeakSet();
var firstObject = {};
var secondObject = {};
// add(value)
weakSetObject.add(firstObject);
weakSetObject.add(secondObject);
console.log(weakSetObject.has(firstObject)); //true
weakSetObject.delete(secondObject);

Related questions

0 votes
0 votes
asked Dec 2, 2022 in JavaScript by john ganales
+1 vote
asked Oct 21, 2021 in Artificial Intelligence by DavidAnderson
...