D3.js | d3.set.clear() Function

The set.clear() function in D3.js is used to remove all values from the set. It clears the set and holds that blank set you can check that in the 2nd example.
Syntax:
d3.set().clear();
Parameters: This function does not accept any parameters.
Return Value: This function does not returns any values.
Below programs illustrate the d3.set.clear() function in D3.js:
Example 1:
| <!DOCTYPE html> <html>  Â<head>     <title> d3.set.clear() Function</title>  Â</head>  Â<body>     <script>  Â        // Initialising the set         varset = d3.set(["1", "2", "a", "b", "Geeks"]);  Â        // Checking the set         console.log(set);         // Calling the set.clear() function         set.clear();  Â        // Checking whether any element is present         // in the set or not         A = set.has("a");         B = set.has("Geeks");  Â        // Getting the output of true or false         console.log(A);         console.log(B);     </script> </body>  Â</html>  | 
Output:
{"$1":"1","$2":"2","$a":"a","$b":"b","$Geeks":"Geeks"}
  false
  false
Example 2:
| <!DOCTYPE html> <html>  Â<head>     <title> d3.set.clear() Function</title>  Â</head>  Â<body>   <script>      Â     // Initialising the set      varset = d3.set(["1", "2", "a", "b", "Geeks"]);       Â     // Checking whether any element is present      // in the set or not before calling set.clear() function      A = set.has("a");      B = set.has("Geeks");       Â     // Getting the output of true or false      console.log(A);      console.log(B);      Â     // Calling the set.clear() function      set.clear();      Â     // Checking whether any element is present      // in the set or not after calling set.clear() function      C = set.has("a");      D = set.has("Geeks");       Â     // Getting the output of true or false      console.log(C);      console.log(D);      Â  </script> </body>  Â</html>  | 
Output:
true true false false
Ref: https://devdocs.io/d3~5/d3-collection#set_clear
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
 
				 
					


