This article explains how to merge multiple arrays into one array using jQuery. There are many ways to do this. Like we can loop through each array and push it to another array one by one or we can join those arrays one by one. Or we can use the jQuery function merge(). But the requirement was a bit different. Since I was using a large amount of data, I was not able to use any loop or any long processes. We will explain in an easy way here in this article. I hope you will like this.
Please see this article in my blog.
Background
Recently I got the requirement for merging large collections of client-side arrays into one array. The problem was the arrays were dynamic, hence I was not sure of the count of the arrays, it may be different at different times. So what to do? A loop, merge, push, join in jQuery was not a perfect solution for me since the data was large. So I found the solution in another way.
Using the code
Assume we have some arrays as follows.
- [21,2], [35,4], [25,6],[11,6],[44,67]
Now we need to change these arrays into a variable.
- var myArrays = [[21,2], [35,4], [25,6],[11,6],[44,67]];
Now here comes the real part.
- var myArray = [].concat.apply([], myArrays);
Now we will write this array to the console.
- console.log(myArray);
See the console, you can get the values as follows.
You can see the demo at jsfiddle here: Merge Multiple Arrays To One.
Conclusion
I hope someone finds this useful. Please share with me your valuable suggestions and feedback. Thanks in advance.


RakeshPosted Aug 19, 2015, 3:57 AM
good work
Sibeesh VenuPosted Aug 19, 2015, 3:28 AM
Jacob Robinson Thank you
Jacob RobinsonPosted Aug 19, 2015, 3:10 AM
Nice One..
Sibeesh VenuPosted Aug 19, 2015, 1:12 AM
Nilesh Jadav Thank you so much
Sibeesh VenuPosted Aug 19, 2015, 1:12 AM
Karthikeyan K Thank you so much
Sibeesh VenuPosted Aug 19, 2015, 1:12 AM
Gowtham K Thank you so much
Sibeesh VenuPosted Aug 19, 2015, 1:11 AM
Shridhar Sharma Thank you so much
Sibeesh VenuPosted Aug 19, 2015, 1:11 AM
Gopi Chand Thank you so much
Sibeesh VenuPosted Aug 19, 2015, 1:11 AM
Santhakumar MunuswamyThank you so much
Sibeesh VenuPosted Aug 19, 2015, 1:11 AM
Rajeesh Menoth Thank you so much
Nilesh JadavPosted Aug 19, 2015, 12:16 AM
Nice share. thanks
Karthikeyan KPosted Aug 18, 2015, 11:11 PM
Good one sir
Gowtham KPosted Aug 18, 2015, 9:16 PM
Good one, Thanks for sharing
Shridhar SharmaPosted Aug 18, 2015, 5:54 PM
nice share :)
Gopi ChandPosted Aug 18, 2015, 2:45 PM
Nice one
Santhakumar MunuswamyPosted Aug 18, 2015, 2:29 PM
Good one
Rajeesh MenothPosted Aug 18, 2015, 2:25 PM
Good One...:)