let arr = [1,2,3]
let newArr = [...arr]
newArr.push(4)
console.log(arr) // [1, 2, 3]
console.log(newArr) //[1,2,3,4]
let arr2 = [[1,2,3],[4,5,6]]
let newArr2 = [...arr2]
newArr2[0].push(100)
console.log(arr2) // [[1,2,3,100],[4,5,6]]
console.log(newArr2) // [[1,2,3,100],[4,5,6]]
总结:当数组是一维数组或对象时是深拷贝,多维时就是浅拷贝
标签:arr,console,log,newArr,解构,let,拷贝,赋值 From: https://www.cnblogs.com/chic-life/p/17686368.html