What you're missing is that you're adding an Array of Arrays to your Array of Arrays. You want to add each individual Array instead.
You can use .apply()
to do this:
mainArray.splice.apply(mainArray, [0,1].concat(arraysToAdd));
So the 0
and 1
arguments you passed are joined with your arraysToAdd
to form the arguments that you're going to pass to .splice()
via .apply()
.
Demo: http://jsfiddle.net/QLwLA/
Without .apply()
, you would have needed to add them individually, like this:
mainArray.splice(0, 1, arraysToAdd[0], arraysToAdd[1], arraysToAdd[2]);