Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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

  • Last Updated : 28 Jun, 2019

The map.size() function in D3.js is used to return the number of entries in the created map.

Syntax:

map.size()

Parameters: This function does not accept any parameters.

Return Value: This function returns the number of entries in the created map.

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

Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <title>d3.map.size() Function</title>
  
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
    <script>
          
        // Creating a map
        var map = d3.map({"Ram": 5, "Geeks": 10, "gfg": 15});
        
        // Calling the map.size() function
        A = map.size();
        
        // Getting the the number of
        // entries in the map.
        console.log(A);
    </script>
</body>
  
</html>

Output:

3

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <title>d3.map.size() Function</title>
  
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
    <script>
          
        // Creating some maps
        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.size() function
        A = map1.size();
        B = map2.size();
        C = map3.size();
        D = map4.size();
      
        // Getting the number of entries in the map.
        console.log(A);
        console.log(B);
        console.log(C);
        console.log(D);
    </script>
</body>
  
</html>

Output:

1
1
2
0

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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!