Sunday, December 29, 2024
Google search engine
HomeLanguagesJavascriptD3.js | d3.map.keys() Function

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

The map.keys() function in D3.js is used to return an array of string keys for every entry in the created map. The order of the returned keys is arbitrary.

Syntax:

map.keys()

Parameters: This function does not accept any parameters.

Return Value: This function returns an array of string keys for every entry in the created map.

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

Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <title>d3.map.keys() function</title>
  
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
    <script>
          
        // Creating a map
        var map = d3.map({"Ram": 5, "Geeks": 10, "gfg": 15});
        
        // Calling the map.keys() function
        A = map.keys();
        
        // Getting an array of string keys for
        // every entry in the map.
        console.log(A);
    </script>
</body>
  
</html>


Output:

["Ram", "Geeks", "gfg"]

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <title>d3.map.keys() function</title>
  
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
    <script>
          
        // Creating some maps
        var map1 = d3.map({"Ram": 5});
        var map2 = d3.map({"Geeks": 10});
        var map3 = d3.map({"Ram": 5, "Geeks": 10});
        var map4 = d3.map();
        
        // Calling the map.keys() function
        A = map1.keys();
        B = map2.keys();
        C = map3.keys();
        D = map4.keys();
        
        // Getting an array of string keys for
        // every entry in the map.
        console.log(A);
        console.log(B);
        console.log(C);
        console.log(D);
    </script>
</body>
  
</html>


Output:

["Ram"]
["Geeks"]
["Ram", "Geeks"]
[]

Ref: https://devdocs.io/d3~5/d3-collection#map_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

Recent Comments