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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title> d3.set.clear() Function</title>
  
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
    <script>
  
        // Initialising the set
        var set = 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>

chevron_right


Output:

{"$1":"1","$2":"2","$a":"a","$b":"b","$Geeks":"Geeks"}
  false
  false

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title> d3.set.clear() Function</title>
  
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
  <script>
      
     // Initialising the set
     var set = 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>

chevron_right


Output:

true
true
false
false

Ref: https://devdocs.io/d3~5/d3-collection#set_clear



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.