so i have this weird problem in JavaScript 'copying' an array:
var a = [0];
var b = a;
b[0]++;
alert(a);
alert(b);
gives me as alerts 1
and 1
while I was expecting 0
and 1
.
If I use slice
to copy the array it works fine:
var a = [0];
var b = a.slice(0);
b[0]++;
alert(a);
alert(b);
Why is this so?
I couldn't find anything at all to explain this problem to me.