I’m wondering why in the following code is the arr2 variable changing if i am using the slice function on the newArr2 variable?
function frankenSplice(arr1, arr2, n) { let newArr = []; let newArr2 = arr2; newArr = newArr2.splice(n, 0,...arr1) console.log(arr2) return newArr2; } frankenSplice([1, 2, 3], [4, 5, 6], 1);
its creating a new variable to equal arr2 so i dont perform the splice on the original arr2 array.
Alright i got it and used slice on the array. Yeah i still havent mastered all of the commands and should go over them again. I probably rushed through the lessons too fast. I am new to programming so all this is still pretty tricky to me.
thanks for the help