Hey I thought I understand this

Tell us what’s happening:
Can somebody please explain why this doesnt work?

“let localArr = arr2;”

I know it works with

“let localArr = arr2.slice();”

but I dont understand why

Your code so far


function frankenSplice(arr1, arr2, n) {
let localArr = arr2.slice();
localArr.splice(n, 0, ...arr1);
return localArr;
}

frankenSplice([1, 2, 3], [4, 5, 6], 1);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36.

Challenge: Slice and Splice

Link to the challenge:

I think slice() creates a copy of an array without changing the original one and it is expected in the task!
The input arrays should remain the same after the function runs.

1 Like

Oh so “let localArr = arr2;” doesnt copy it, it just links to arr2?