数组1给数组2赋值后,用unshift更改数组2后,数组1也增加了同样的元素?
代码如下:
var shops2=[1,2,3]
var shops1=shops2
shops1.unshift("所有门店")
console.log("shops2:",shops2,"shops1:",shops1)
输出结果如下:
shops2: (4) ["所有门店", 1, 2, 3],shops1: (4) ["所有门店", 1, 2, 3]
2 回复