Skip to content
Related Articles
Open in App
Not now

Related Articles

D3.js | d3.entries() Function

Improve Article
Save Article
  • Last Updated : 03 May, 2021
Improve Article
Save Article

Disclaimer: in version 6 of D3.js function d3.entries got deprecated. Object.entries should be used instead.

The d3.entries function in D3.js is used to return an array containing the property names and property values of the specified object.
Syntax: 
 

d3.entries(object)

Parameters: the function accepts a single parameter — a JavaScript object.
Return Value: It returns an array containing the property names and values of the specified object.
The programs below illustrate the d3.entries function in D3.js:
Example 1: 
 

javascript




<!DOCTYPE html>
<html>
     
<head>
    <title> d3.entries() function</title>
         
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
<body>
     
<script>
      
     // Initialising an object
     var month = {"January": 1, "February": 2, "March": 3};
           
     // Calling the d3.entries() function
     A = d3.entries(month);
       
     // Getting the key and value in pairs
     console.log(A);
  </script>
</body>
</html>

Output: 
 

[{"key":"January","value":1},{"key":"February","value":2},
                                       {"key":"March","value":3}]

Example 2: 
 

javascript




<!DOCTYPE html>
<html>
     
<head>
    <title> d3.entries function</title>
         
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
<body>
  <script>
      
     // Initialising an object
     var month = {"GeeksforGeeks": 0, "Geeks": 2,
                                     "Geek": 3, "gfg": 4};
           
     // Calling the d3.entries function
     A = d3.entries(month);
       
     // Getting the key and value in pairs.
     console.log(A);
  </script>
</body>
</html>

Output: 
 

[{"key":"GeeksforGeeks","value":0},{"key":"Geeks","value":2},
                     {"key":"Geek","value":3},{"key":"gfg","value":4}]

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


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!