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

Last Updated : 28 Jun, 2022

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: 

javascript
<!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 number of
        // entries in the map.
        console.log(A);
    </script>
</body>

</html>

Output:

3

Example 2: 

javascript
<!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>
Comment

Explore