Saturday, September 6, 2025
HomeLanguagesJavascriptD3.js | d3.map.has() Function

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

The map.has() function in D3.js is used to return true if the created map has an entry for specified key string. The value of map.has() function may be null or undefined.

Syntax:

map.has(key)

Parameters: This function accepts single parameter key which is specified the key string.

Return Value: This function returns true if created map has an entry for the specified key string. The value may be null or undefined.

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

Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <title>d3.map.has() function</title>
  
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
    <script>
          
        // Creating a map
        var map = d3.map({"Ram": 5});
        
        // Calling the map.has() function
        A = map.has("Ram");
        B = map.has("Geeks");
        
        // Getting the true if the map
        // has an entry for the specified key string
        // else false
        console.log(A);
        console.log(B);
    </script>
</body>
  
</html>


Output:

true
false

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <title>d3.map.has() function</title>
  
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
    <script>
          
        // Creating a map
        var map1 = d3.map({"Ram": 5});
        var map2 = d3.map({"Geeks": 10});
        var map3 = d3.map({"Ram": 5}, {"Geeks": 10});
        var map4 = d3.map();
        
        // Calling the map.has() function
        A = map1.has("Ram");
        B = map2.has("Geeks");
        C = map3.has("Geeks");
        D = map3.has("Ram");
        E = map4.has("Geeks");
        
        // Getting the true if the map
        // has an entry for the specified key string
        // else false
        console.log(A);
        console.log(B);
        console.log(C);
        console.log(D);
        console.log(E);
    </script>
</body>
  
</html>


Output:

true
true
false
true
false

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

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
32269 POSTS0 COMMENTS
Milvus
82 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11868 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS