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>
</head>
<body>
<script>
var map = d3.map({"Ram": 5, "Geeks": 10, "gfg": 15});
A = map.size();
console.log(A);
</script>
</body>
</html>
|
Output:
3
Example 2:
javascript
<!DOCTYPE html>
<html>
<head>
<title>d3.map.size() Function</title>
</head>
<body>
<script>
var map1 = d3.map({"Ram": 5});
var map2 = d3.map({"Geeks": 10});
var map3 = d3.map({"Ram": 5, "Geeks": 10});
var map4 = d3.map();
A = map1.size();
B = map2.size();
C = map3.size();
D = map4.size();
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...