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 18, 2015, 11:57 PM EDT
good work
Sibeesh VenuTOP 100Posted Aug 18, 2015, 11:28 PM EDT
Jacob Robinson Thank you
Jacob RobinsonPosted Aug 18, 2015, 11:10 PM EDT
Nice One..
Sibeesh VenuTOP 100Posted Aug 18, 2015, 9:12 PM EDT
Nilesh Jadav Thank you so much
Sibeesh VenuTOP 100Posted Aug 18, 2015, 9:12 PM EDT
Karthikeyan K Thank you so much
Sibeesh VenuTOP 100Posted Aug 18, 2015, 9:12 PM EDT
Gowtham K Thank you so much
Sibeesh VenuTOP 100Posted Aug 18, 2015, 9:11 PM EDT
Shridhar Sharma Thank you so much
Sibeesh VenuTOP 100Posted Aug 18, 2015, 9:11 PM EDT
Gopi Chand Thank you so much
Sibeesh VenuTOP 100Posted Aug 18, 2015, 9:11 PM EDT
Santhakumar MunuswamyThank you so much
Sibeesh VenuTOP 100Posted Aug 18, 2015, 9:11 PM EDT
Rajeesh Menoth Thank you so much
Nilesh JadavPosted Aug 18, 2015, 8:16 PM EDT
Nice share. thanks
Karthikeyan KPosted Aug 18, 2015, 7:11 PM EDT
Good one sir
Gowtham KTOP 100Posted Aug 18, 2015, 5:16 PM EDT
Good one, Thanks for sharing
Shridhar SharmaPosted Aug 18, 2015, 1:54 PM EDT
nice share :)
Gopi ChandPosted Aug 18, 2015, 10:45 AM EDT
Nice one
Santhakumar MunuswamyPosted Aug 18, 2015, 10:29 AM EDT
Good one
Rajeesh MenothPosted Aug 18, 2015, 10:25 AM EDT
Good One...:)