Monday, November 18, 2024
Google search engine
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

Recent Comments