Sunday, May 10, 2026
HomeLanguagesJavascriptD3.js | d3.map.remove() Function

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

The map.remove() function is an inbuilt function in D3.js. If the created map contains the given key string then it removes the entry and returns true. If key string not presents then it returns false.

Syntax:

map.remove(key)

Parameters: This function accepts single parameter key which is used to specify the key string.

Return Value: This function returns true if the created map has an entry for the specified key string otherwise returns false.

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

Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <title>d3.map.remove() 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.remove() function
        A = map.remove("Ram");
        B = map.remove("Geek");
        C = map.remove("Geeks");
            
        // Getting true if the map has an
        // entry for the specified key string 
        // otherwise returns false.
        console.log(A);
        console.log(B);
        console.log(C);
    </script>
</body>
  
</html>


Output:

true
false
true

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <title>d3.map.remove() 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.remove() function
        A = map1.remove("Ram");
        B = map2.remove("Geek");
        C = map3.remove("Shyam");
        D = map4.remove("Ram");
        
        // Getting true if the map has an
        // entry for the specified key string 
        // otherwise returns false.
        console.log(A);
        console.log(B);
        console.log(C);
        console.log(D);
    </script>
</body>
  
</html>


Output:

true
false
false
false

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

RELATED ARTICLES

1 COMMENT

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