Is there a way to use Array.splice in javascript with the third parameter as an array? Is there a way to use Array.splice in javascript with the third parameter as an array? arrays arrays

Is there a way to use Array.splice in javascript with the third parameter as an array?


Array.splice supports multiple arguments after the first two. Those arguments will all be added to the array. Knowing this, you can use Function.apply to pass the array as the arguments list.

var a1 = ['a', 'e', 'f'];var a2 = ['b', 'c', 'd'];// You need to append `[1,0]` so that the 1st 2 arguments to splice are sentArray.prototype.splice.apply(a1, [1,0].concat(a2));


With ES6, you can use the spread operator. It makes it much more concise and readable.

var a1 = ['a', 'e', 'f'];var a2 = ['b', 'c', 'd'];a1.splice(1, 0, ...a2);console.log(a1)