当我遇到一些奇怪的事情时,我正在使用 JavaScript 中的一些数组。这是我的代码:
var origArray = new Array("one","two","three","four","five","six","seven","eight");
var newArray = origArray.slice(1,3);
origArray[1] = "octopus";
console.log(newArray.join()); //prints two,three
var origArray = new Array(["one","two"],["three","four"],["five","six"],["seven","eight"]);
var newArray = origArray.slice(1,3);
origArray[1][0] = "octopus";
console.log(newArray.join()); //prints octopus,four,five,six
我不明白为什么newArray
在第二种情况而不是第一种情况下会受到影响。这里发生了什么?