Thursday, November 20, 2025
HomeLanguagesJavascriptD3.js | d3.map.size() Function

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

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>


Output:

1
1
2
0

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

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
32404 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6776 POSTS0 COMMENTS
Nicole Veronica
11925 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11994 POSTS0 COMMENTS
Shaida Kate Naidoo
6905 POSTS0 COMMENTS
Ted Musemwa
7160 POSTS0 COMMENTS
Thapelo Manthata
6861 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS