D3.js | d3.pairs() function
Last Updated :
28 Jun, 2019
The d3.pairs() function in D3.js is used to create pair of array elements from the given array elements. If the given array is having less than two elements then it returns the empty array.
Syntax:
d3.pairs(Array)
Parameters: This function accepts a parameter Array whose elements are going to be paired.
Return Value: It returns the array of paired elements.
Below programs illustrate the d3.pairs() function in D3.js.
Example 1:
<html>
<head>
<title>
Getting pair of two elements
from the elements of given array
</title>
</head>
<body>
</script>
<script>
var Array1 = [10, 20, 30, 40];
var Array2 = [1, 2, 3, 4];
A = d3.pairs(Array1);
B = d3.pairs(Array2);
document.write(A + "<br>" );
document.write(B + "<br>" );
</script>
</body>
</html>
|
Output:
[[10, 20], [20, 30], [30, 40]]
[[1, 2], [2, 3], [3, 4]]
Example 2:
<html>
<head>
<title>
Getting pair of two elements
from the elements of given array
</title>
</head>
<body>
</script>
<script>
var Array1 = [ "A" , "B" , "C" ];
var Array2 = [ "a" , "b" ];
A = d3.pairs(Array1);
B = d3.pairs(Array2);
document.write(A + "<br>" );
document.write(B + "<br>" );
</script>
</body>
</html>
|
Output:
[[A, B], [B, C]]
[a, b]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...