Splice with array

How to replace part of an array with the contents of another array.

by Göran Andersson

JavaScript

var arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
var anotherArr = [1, 2, 3];

Array.prototype.splice.apply(arr, [0, anotherArr.length].concat(anotherArr));

console.log(arr);