当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


d3.js d3.map.clear()用法及代码示例


D3.js中的map.clear()函数用于从创建的Map中删除所有条目。

用法:

d3.map.clear();

参数:该函数不接受任何参数。


返回值:此函数不返回任何值。

以下程序说明了D3.js中的d3.map.clear()函数:

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

输出:

undefined

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

输出:

0
undefined

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



相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 D3.js | d3.map.clear() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。