Related Articles

Related Articles

D3.js | d3.keys() Function
  • Last Updated : 28 Jun, 2019

The d3.keys() function in D3.js is used to return an array containing the property names or keys of the specified object or an associative array.

Syntax:

d3.keys(object)

Parameters: This function accepts single parameter object containing key and value in pairs.

Return Value: It returns the keys of the given object.

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



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        d3.keys() 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,
            "April": 4
        };
              
        // Calling the d3.keys() function
        A = d3.keys(month);
        
        // Getting the key values of the given object
        document.write(A);
    </script>
</body>
  
</html>                    

chevron_right


Output:

January, February, March, April

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        d3.keys() 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.keys() function
        A = d3.keys(month);
        
        // Getting the key values of the given object
        document.write(A);
    </script>
</body>
  
</html>                    

chevron_right


Output:

GeeksforGeeks, Geeks, Geek, gfg

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

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :