Tuesday, June 16, 2026
HomeLanguagesJavascriptD3.js | d3.set.add() Function

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

The set.add() function in D3.js is used to add the specified value string to the created set.

Syntax:

d3.set().add(element);

Parameters: This function accepts single parameter element which is going to be added into the created set.

Return Value: This function does not returns any values.

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

Example 1:




<!DOCTYPE html>
  
<html>
   
<head>
    <title> d3.set.add() Function</title>
   
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
  <script>
      
     // Initialising the set
     var set = d3.set()
    .add("Geeks")
    .add("Geeks")
    .add("gfg");
  
    // Checking whether the desired element is 
    // present or not
    A = set.has("neveropen");
    B = set.has("Ram");
    C = set.has("Geeks");
      
    // Getting the output of true or false
    console.log(A);
    console.log(B);
    console.log(C);
  </script>
</body>
  
</html>


Output:

false
false
true

Example 2:




<!DOCTYPE html>
  
<html>
   
<head>
    <title> d3.set.add() Function</title>
   
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
  <script>
      
     // Initialising the set
     var set = d3.set().add("a").add(1).add(123);
  
    // Checking whether the desired element is 
    // present or not
    A = set.has("a");
    B = set.has(123);
    C = set.has(5);
      
    // Getting the output of true or false
    console.log(A);
    console.log(B);
    console.log(C);
  </script>
</body>
  
</html>


Output:

true
true
false

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!
RELATED ARTICLES

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS