當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


d3.js d3.map.empty()用法及代碼示例

如果創建的包含零個條目的映射返回D3.js中的map.empty()函數,則返回true。

用法:

map.empty();

參數:該函數不接受任何參數。


返回值:如果映射為空,則此函數返回true,否則返回false。

以下程序說明了D3.js中的d3.map.empty()函數:

範例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>

輸出:

false
true

範例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>

輸出:

false
false
true
true

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



相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 D3.js | d3.map.empty() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。