Friday, May 15, 2026
HomeLanguagesJavascriptD3.js | d3.map.clear() Function

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

The map.clear() function in D3.js used to remove all the entries from the created map.

Syntax:

d3.map.clear();

Parameters: This function does not accept any parameter.

Return Value: This function does not return any values.

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

Example 1:




<!DOCTYPE html>
<html>
    
<head>
    <title> d3.map.clear() Function</title>
    
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
  <script>
       
     // Creating a map
     var map = d3.map({"a": 1}, {"b": 2}, {"c": 3});
   
     // Calling the map.clear() function
     map.clear();
        
     // Checking whether the value for the specified key 
     // is present or not
     A = map.get("a");
        
    // Getting the output either value of the specified key
    // string or undefined if the key is not present
    console.log(A);
       
  </script>
</body>
  
</html>


Output:

undefined

Example 2:




<!DOCTYPE html>
<html>
    
<head>
    <title> d3.map.clear() Function</title>
    
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
  <script>
       
     // Constructing a map
     var map = d3.map({"a": 0}, {"b": 1}, {"c": 2});
        
     // Checking whether the value for the specified key
     // is present or not before calling clear() function
     A = map.get("a");
        
     // Getting the output of value
     console.log(A);
       
     // Calling the map.clear() function
     map.clear();
       
     // Checking whether the value for the specified key
     // is present or not after calling clear() function
     B = map.get("a");
        
     // Getting the output of value
     console.log(B);
  </script>
</body>
  
</html>


Output:

0
undefined

Ref: https://devdocs.io/d3~5/d3-collection#map_clear

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

2 COMMENTS

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS