How to replace elements in array with elements of another array

http://stackoverflow.com/q/17511273/1321716

by MattiasBuelens

JavaScript

var arr = new Array(10),
    anotherArr = [1, 2, 3];

// Clone the original array
var result = arr.slice(0);
// If original array is no longer needed, you can do with:
// var result = arr;

// Remove (anotherArr.length) elements starting from index 0
// and insert the elements from anotherArr into it
Array.prototype.splice.apply(result, [0, anotherArr.length].concat(anotherArr));

console.log("arr: ", arr);
console.log("anotherArr: ", anotherArr);
console.log("result: ", result);