That is because there is only one array - simply, both variables name the same array. Just like a person (with nicknames), a single object can have many names.
The =
(assignment) operator in JavaScript does not copy/clone/duplicate the object being assigned.
The Array.splice
function mutates the array (of which there is only one) which, when taken with the above, explains the behavior.
To create a shallow clone of an array, arr.slice(0)
can be useful.