Im trying to find simplest way to merge two arrays into the third one, with jQuery, like this:
[A,B,C,D]
[1,2,3,4]
The answer would be:
[A,1,B,2,C,3,D,4]
Another example:
[A,B,C] + [1,2,3,4,5] = [A,1,B,2,C,3,4,5]
[A,B,C,D] + [1,2,3] = [A,1,B,2,C,3,D]
You can directly create an Array using the
jQuery.map()[docs] method. When you return an Array,jQuery.mapdoes a.concat().This will also prevent holes in the Array when lengths differ.
http://jsfiddle.net/zbCj7/
or a little more concise:
http://jsfiddle.net/zbCj7/1/
If you really want to make it concise, you could do this:
http://jsfiddle.net/zbCj7/2/