Open In App

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

Last Updated : 28 Jun, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The map.empty() function in D3.js is used to return true if the created map containing zero entries otherwise returns false.

Syntax:

map.empty();

Parameters: This function does not accept any parameter.

Return Value: This function returns true if the map is empty otherwise returns false.

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

Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <title>
        d3.map.empty() Function
    </title>
      
    <script src = "https://d3js.org/d3.v4.min.js"></script>
</head>
  
<body>
    <script>
          
        // Creating a map
        var map1 = d3.map({"a": 1}, {"b": 2}, {"c": 3});
        var map2 = d3.map();
      
        // Calling the map.empty() function
        A = map1.empty();
        B = map2.empty();
          
        // Getting the result whether the maps are empty or not
        console.log(A);
        console.log(B);
    </script>
</body>    
  
</html>


Output:

false
true

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <title>
        d3.map.empty() Function
    </title>
      
    <script src = "https://d3js.org/d3.v4.min.js"></script>
</head>
  
<body>
    <script>
          
        // Creating a map
        var map1 = d3.map({"a": 1}, {"b": 2}, {"c": 3});
        var map2 = d3.map({"GFG": 5});
        var map3 = d3.map({});
        var map4 = d3.map();
        
        // Calling the map.empty() function
        A = map1.empty();
        B = map2.empty();
        C = map3.empty();
        D = map4.empty();
        
        // Getting the result whether
        // the maps are empty or not
        console.log(A);
        console.log(B);
        console.log(C);
        console.log(D);
    </script>
</body>    
  
</html>


Output:

false
false
true
true

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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads