Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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

  • Last Updated : 28 Jun, 2019

The map.entries() function in D3.js used to return an array of key-value objects for the entry in the created map.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

d3.map.entries();

Parameters: This function does not accept any parameter.

Return Value: This function returns an array of key-value pair for the entry in the created map.



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

Example 1:




<!DOCTYPE html>
<html>
    
<head>
    <title>d3.map.entries() Function</title>
    
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
  <script>
       
     // Creating a map
     var map1 = d3.map({"a": 1});
     var map2 = d3.map({"GFG": 5});
       
     // Calling the map.entries() function
     A = map1.entries();
     B = map2.entries();
       
     // Getting the array of key value pair
     console.log(A);
     console.log(B);
  </script>
</body>
  
</html>

Output:

[{"key":"a", "value":1}]
[{"key":"GFG", "value":5}]

Example 2:




<!DOCTYPE html>
<html>
    
<head>
    <title>d3.map.entries() Function</title>
    
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
  <script>
       
     // Creating a map
     var map1 = d3.map({"Ram": 5}, {"Geek": 10});
     var map2 = d3.map();
       
     // Calling the map.entries() function
     A = map1.entries();
     B = map2.entries();
       
     // Getting the array of key value pair
     console.log(A);
     console.log(B);
  </script>
</body>
  
</html>

Output:

[{"key":"Ram", "value":5}]
[]

Note: Map2 was null that is why it’s became blank.

Reference: https://devdocs.io/d3~5/d3-collection#map_entries




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!