Menu ▼



Posted By :
avatarmrkraju
Total Views : 353

jQuery merge function to merge the content of two arrays

jQuery.merge() function is used to merge the content of two arrays. merge function will merge the content of two arrays into the first array.

Example 1
Below example will merge the first array elements and second array elements into first array.

Two arrays:

var firstary = ["one", "two", "three"];
var secondary = ["four", "five", "six"];

Merge Two arrays
$.merge(firstary, secondary);

Output
firstary -> ["one", "two", "three", "four", "five", "six"];
secondary -> ["four", "five", "six"];

Example 2
Below example will merge the first array elements and second array elements into new array and keeps the first and second array elements as it is.

Two arrays:

var firstary = ["one", "two", "three"];
var secondary = ["four", "five", "six"];

Merge Two arrays into new array
var thirdary = $.merge($.merge([], firstary), secondary);

Output
firstary -> ["one", "two", "three"];
secondary -> ["four", "five", "six"];
thirdary -> ["one", "two", "three", "four", "five", "six"];






comments powered by Disqus


Search dotnetlearners.com