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

The set.has() function in D3.js is used to return true if and only if the given set containing an entry for the specified value.

Syntax:

d3.set([Array]).has(element);

Parameters: This function accepts two parameters as mentioned above and described below:

  • Array: It store the array elements in form of string.
  • element: This is the value which is going to be searched into the given array and if present then it returns true otherwise returns false.

Return Value: It returns true if the given array contains the specified value, otherwise returns false.

Below programs illustrate the d3.set.has() function in D3.js:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        d3.set.has() function
    </title>
      
    <script src = "https://d3js.org/d3.v4.min.js"></script>
</head>
  
<body>
    <script>
      
        // Initialising an array
        Array1 = ["a", "a", "b", "c"];
        Array2 = ["c", "c", "c"];
        Array3 = ["Geeks", "gfg", "GeeksforGeeks"];
          
        // Calling the d3.set.has() function
        A = d3.set(Array1).has("a");
        B = d3.set(Array2).has("a");
        C = d3.set(Array3).has("Geeks");
          
        // Getting the value true if the specified element
        // is present in the array otherwise false
        console.log(A);
        console.log(B);
        console.log(C);
    </script>
</body>
  
</html>

chevron_right


Output:

true
false
true

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        d3.set.has() function
    </title>
      
    <script src = "https://d3js.org/d3.v4.min.js"></script>
</head>
  
<body>
    <script>
      
        // Calling the d3.set.has() function
        // with a array and a element as the parameter 
        A = d3.set([1, 2, 3, 3]).has(4);
        B = d3.set(["a"]).has("a");
        C = d3.set(["a", "b", "c", "a", "b", "c"]).has("d");
            
        // Getting the value true if the specified element
        // is present in the array otherwise false
        console.log(A);
        console.log(B);
        console.log(C);
    </script>
</body>
  
</html>

chevron_right


Output:

false
true
false

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



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.