如果給定數組的元素為零,則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
相關用法
- PHP cos( )用法及代碼示例
- PHP sin( )用法及代碼示例
- p5.js nfc()用法及代碼示例
- d3.js d3.set.add()用法及代碼示例
- p5.js nfp()用法及代碼示例
- PHP abs()用法及代碼示例
- p5.js nf()用法及代碼示例
- d3.js d3.map.has()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- CSS var()用法及代碼示例
- p5.js box()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 D3.js | d3.set.empty() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。