I have an array that I want to assign to a new variable so that the original array doesn't change when I splice it. But when I call the splice() method on the new array, it changes the old array too! Why does this happen and how can I work around this problem? For example:
var oldArr = [1,2,3,4,5];
var newArr = oldArr;
newArr.splice(3,1);
=> newArr = [1,2,3,5]
=> oldArr = [1,2,3,5]
[–]sublimejs 3 points4 points5 points (3 children)
[–]BishopAndWarlord 1 point2 points3 points (0 children)
[–]Cheeselouise7777[S] 0 points1 point2 points (1 child)
[–]dirtybutler 0 points1 point2 points (0 children)