Please see the below code and it's corresponding output when ran on chrome console.
var x = [1,2,3,4,5,6,7,8]
var y = x;
console.log(y.length);
x.splice(1,1);
console.log(y.length);
console.log(x.length);
The output is as follows:
8
7
7
My query is since I've initialized the variable y
before splicing x
, then why the y
is getting spliced automatically. Thanks in advance.