D3.js | d3.merge() function

The d3.merge() function in D3.js is used to merge the two given array 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.

Below programs illustrate the d3.merge() function in D3.js.
Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<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
        var Array1 = [10, 20, 30];
        var 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>

chevron_right


Output:

[10, 20, 30, 1, 2, 3]

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<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
        var Array1 = ["A", "B", "C"];
        var 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>

chevron_right


Output:

[A, B, C, a, b, c]

Ref: https://devdocs.io/d3~4/d3-array#merge



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.