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


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


D3.js中的set.clear()函数用于从集中删除所有值。它清除该集并保留该空白集,您可以在第二个示例中进行检查。

用法:

d3.set().clear();

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


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

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

示例1:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> d3.set.clear() Function</title> 
  
    <script src='https://d3js.org/d3.v4.min.js'></script> 
</head> 
  
<body> 
    <script> 
  
        // Initialising the set 
        var set = d3.set(["1", "2", "a", "b", "Geeks"]); 
  
        // Checking the set 
        console.log(set); 
        // Calling the set.clear() function 
        set.clear(); 
  
        // Checking whether any element is present 
        // in the set or not 
        A = set.has("a"); 
        B = set.has("Geeks"); 
  
        // Getting the output of true or false 
        console.log(A); 
        console.log(B); 
    </script> 
</body> 
  
</html>

输出:

{"$1":"1","$2":"2","$a":"a","$b":"b","$Geeks":"Geeks"}
  false
  false

示例2:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> d3.set.clear() Function</title> 
  
    <script src='https://d3js.org/d3.v4.min.js'></script> 
</head> 
  
<body> 
  <script> 
      
     // Initialising the set 
     var set = d3.set(["1", "2", "a", "b", "Geeks"]); 
       
     // Checking whether any element is present 
     // in the set or not before calling set.clear() function 
     A = set.has("a"); 
     B = set.has("Geeks"); 
       
     // Getting the output of true or false 
     console.log(A); 
     console.log(B); 
      
     // Calling the set.clear() function 
     set.clear(); 
      
     // Checking whether any element is present 
     // in the set or not after calling set.clear() function 
     C = set.has("a"); 
     D = set.has("Geeks"); 
       
     // Getting the output of true or false 
     console.log(C); 
     console.log(D); 
      
  </script> 
</body> 
  
</html>

输出:

true
true
false
false

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



相关用法


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