Ran in to this and I can't find documentation explaining the change- why does .push() change an array when it's applied to a new array that is set equal to that original array?
ex:
var arr = [1, 2, 3, 4, 5]
var newarr = arr
newarr.push(3)
console.log(newarr) //returns [1, 2, 3, 4, 5, 3] as expected
console.log(arr) //returns [1, 2, 3, 4, 5, 3] as well
What's happening here? I'm not applying any methods to arr (that I can see). It looks like arr and newarr are still linked in a way that doesn't apply to other variables, or .push() is invoking the newarr assignment line somehow?
For contrast, this is analogous to what I was expecting-
var x=6
var y=x
y=y*6
console.log(y) // now 36
console.log(x) // still six