D3.js | d3.map.get() Function
The map.get() function in D3.js is used to return the value for the specified key string. If the created map does not contain the specified key then it returns undefined.
Syntax:
map.get(key)
Parameters: This function accepts single parameter key which is used to specify the key string.
Return Value: This function returns the value for the specified key string. If the created map does not have an entry for the specified key, returns undefined.
Below programs illustrate the d3.map.get() function in D3.js:
Example 1:
<!DOCTYPE html> <html> <head> <title>d3.map.get() function</title> </head> <body> <script> // Creating a map var map = d3.map({"Ram": 5}); // Calling the map.get() function A = map.get("Ram"); // Getting the value for the "Ram" key console.log(A); </script> </body> </html> |
Output:
5
Example 2:
<!DOCTYPE html> <html> <head> <title>d3.map.get() function</title> </head> <body> <script> // Creating a map 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.get() function A = map1.get("Ram"); B = map2.get("Geeks"); C = map3.get("Geeks"); D = map3.get("Ram"); E = map4.get("Geeks"); // Getting the values for // the specified keys console.log(A); console.log(B); console.log(C); console.log(D); console.log(E); </script> </body> </html> |
Output:
5 10 undefined 5 undefined
Ref: https://devdocs.io/d3~5/d3-collection#map_get
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- PHP | abs() Function
- D3.js | d3.min() function
- p5.js | hue() function
- PHP | sin( ) Function
- p5.js | max() function
- PHP | Ds\Map get() Function
- p5.js | red() function
- D3.js | d3.sum() function
- p5.js | cos() function
- PHP | next() Function
- p5.js | min() function
- p5.js | log() function
- PHP | each() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



