Friday, June 12, 2026
HomeLanguagesJavascriptD3.js | d3.keys() Function

D3.js | d3.keys() Function

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:




<!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>                    


Output:

January, February, March, April

Example 2:




<!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 = {
            "neveropen": 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>                    


Output:

neveropen, Geeks, Geek, gfg

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

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

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS