To replace the elements in an array with the elements of another array

We can replace part of an array with items from another array, 

var array1 = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
var array2 = [ 1, 2, 3 ];
Array1.prototype.splice.apply(Array1, [0, Array2.length].concat(Array2));

Then, array1 = [ 1, 2, 3, 'd', 'e', 'f', 'g', 'h', 'i', 'j']

Leave a comment

Your email address will not be published. Required fields are marked *