D3.js中的d3.pairs()函數用於根據給定的數組元素創建一對數組元素。如果給定數組的元素少於兩個,則它將返回空數組。
用法:
d3.pairs(Array)
參數:此函數接受參數Array,其元素將配對。
返回值:它返回配對元素的數組。
以下程序說明了D3.js中的d3.pairs()函數。
示例1:
<html> 
  
<head> 
    <title> 
      Getting pair of two elements  
      from the elements of given array 
  </title> 
</head> 
  
<body> 
    <script src='https://d3js.org/d3.v4.min.js'> 
  </script> 
  
    <script> 
        // initialising the arrays of elements 
        var Array1 = [10, 20, 30, 40]; 
        var Array2 = [1, 2, 3, 4]; 
  
        // Calling to d3.pairs() function 
        A = d3.pairs(Array1); 
        B = d3.pairs(Array2); 
  
        // Getting pair of two elements from  
        // the elements of given array 
        document.write(A + "<br>"); 
        document.write(B + "<br>"); 
    </script> 
</body> 
  
</html>輸出:
[[10, 20], [20, 30], [30, 40]] [[1, 2], [2, 3], [3, 4]]
示例2:
<html> 
  
<head> 
    <title> 
      Getting pair of two elements 
      from the elements of given array 
  </title> 
</head> 
  
<body> 
    <script src='https://d3js.org/d3.v4.min.js'> 
  </script> 
  
    <script> 
        // initialising the arrays of elements 
        var Array1 = ["A", "B", "C"]; 
        var Array2 = ["a", "b"]; 
  
        // Calling to d3.pairs() function 
        A = d3.pairs(Array1); 
        B = d3.pairs(Array2); 
  
        // Getting pair of two elements from 
        // the elements of given array 
        document.write(A + "<br>"); 
        document.write(B + "<br>"); 
    </script> 
</body> 
  
</html>輸出:
[[A, B], [B, C]] [a, b]
相關用法
- p5.js cos()用法及代碼示例
- d3.js d3.hsl()用法及代碼示例
- p5.js log()用法及代碼示例
- p5.js tan()用法及代碼示例
- PHP pos()用法及代碼示例
- d3.js d3.sum()用法及代碼示例
- PHP key()用法及代碼示例
- p5.js sin()用法及代碼示例
- p5.js second()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP each()用法及代碼示例
- PHP each()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 D3.js | d3.pairs() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
