I have come across a strange bug in my code and I cannot understand why it happens.
I have an array array1. I duplicate array1 by making array2 equal to array1. I then modify array2 using splice to add a number. Array1 should not be touched? But both output the same change.
var array1 = [0,1,2,3,4,5];
var array2 = array1;
array2.splice(1,0,1) //add
console.log(array1);
console.log(array2);
I am assuming I am confusing array assignment? What is the proper way to duplicate arrays without this happening?
Cheers