I need to push array of elements inside another array at a particular index in javascript without using spread operator and without using another array.
Input:
let firstArray = [4,5,6];
let secondArray = [1,2,3,7,8,9];
Expected Output:
console.log(secondArray); //[1,2,3,4,5,6,7,8,9];
I tried using splice and apply function like below.
let firstArray = [4,5,6];
let secondArray = [1,2,3,7,8,9];
firstArray.splice(0, 0, 3, 0);
secondArray.splice.apply(secondArray, firstArray);
This code gives expected output but also updating the elements in firstArray before updating the secondArray.
Is there any better way to achieve the expected output without updating the elements in firstArray?
Edit 1: I am trying to achieve this without new array because the size of the firstArray and secondArray are huge. Thus feeling it might create unwanted memory allocation for new array to just push elements into another array. Avoiding spread operator as it is not supported in IE browsers Edit 2: Removed without using loops condition.