The d3.merge() function in D3.js is used to merge the two given arrays into a single array.
Syntax:
d3.merge(Array1, Array2)Parameters:
This function accepts two parameters which are mentioned above and described below:
- Array1: This is the first array whose elements are going to be merged with array2.
- Array2: This is the second array whose elements are going to be merged with array1.
Return Value:
It returns the merged single array.
Example 1: This example shows the use of the merge() function.
<!DOCTYPE html>
<html>
<head>
<title>Getting a single array after
merging of the two given array
</title>
</head>
<body>
<script src=
'https://d3js.org/d3.v4.min.js'>
</script>
<script>
// initialising the arrays of elements
let Array1 = [10, 20, 30];
let Array2 = [1, 2, 3];
// Calling to d3.merge() function
A = d3.merge([
[Array1],
[Array2]
]);
// Getting a single array after
// merging of the two given array
document.write(A + "<br>");
</script>
</body>
</html>
Output:
[10, 20, 30, 1, 2, 3]Example 2: This example shows the use of the merge() function.
<!DOCTYPE html>
<html>
<head>
<title>
Getting a single array after
merging of the two given array
</title>
</head>
<body>
<script src=
'https://d3js.org/d3.v4.min.js'>
</script>
<script>
// initialising the arrays of elements
let Array1 = ["A", "B", "C"];
let Array2 = ["a", "b", "c"];
// Calling to d3.merge() function
A = d3.merge([
[Array1],
[Array2]
]);
// Getting a single array
// after merging of the two given array
document.write(A + "<br>");
</script>
</body>
</html>
Output:
[A, B, C, a, b, c]