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


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


如果给定数组的元素为零,则D3.js中的set.empty()函数用于返回true,否则返回false。

用法:

d3.set([Array]).empty();

参数:此函数接受单个参数Array,无论该参数是否为空,都将对其进行搜索。


返回值:如果给定数组为空,则返回true,否则返回false。

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

示例1:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        d3.set.empty() function
    </title> 
      
    <script src = "https://d3js.org/d3.v4.min.js"></script> 
</head> 
  
<body> 
    <script> 
      
         // Initialising an array 
         Array1 = ["a"]; 
         Array2 = []; 
         Array3 = ["Geeks", "gfg", "GeeksforGeeks"]; 
            
         // Calling the d3.set.empty() function 
         A = d3.set(Array1).empty(); 
         B = d3.set(Array2).empty(); 
         C = d3.set(Array3).empty(); 
            
         // Getting the value true if the given array is  
         // empty otherwise returns false 
         console.log(A); 
         console.log(B); 
         console.log(C); 
    </script> 
</body> 
  
</html>                    

输出:

false
true
false

示例2:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        d3.set.empty() function
    </title> 
      
    <script src = "https://d3js.org/d3.v4.min.js"></script> 
</head> 
  
<body> 
    <script> 
      
        // Calling the d3.set.empty() function 
        // with a array as the parameter  
        A = d3.set([1, 2, 3, 3]).empty(); 
        B = d3.set([]).empty(); 
        C = d3.set(["a", "b", "c", "a", "b", "c"]).empty(); 
        
        // Getting the value true if the given array is 
        // empty otherwise returns false 
        console.log(A); 
        console.log(B); 
        console.log(C); 
    </script> 
</body> 
  
</html>                    

输出:

false
true
false

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



相关用法


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