在 JavaScript 中,数组是对象,因此通过引用传递。所以
var a = ["a"];
var b = a;
console.log(b);
a[0] = "wtv";
console.log(b);
将改变b值。
我不明白的是为什么
var a = ["a"];
var b = a;
console.log(b);
a = ["wtv"];
console.log(b);
没有改变b值吗?这背后的原因是什么?
最佳答案
关于javascript - 数组重新/赋值引用更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34704527/