js如何清空一个数组
方法1
let arr1 = [1,2,3]
let arr2 = arr1
arr1 = []
console.log(arr1,arr2) // [] [1,2,3]
方法2
const arr1 = [1,2,3]
const arr2 = arr1
arr1.length = 0
console.log(arr1,arr2) // [] []
方法3
const arr1 = [1,2,3]
const arr2 = arr1
let res = arr1.splice(0,arr1.length)
console.log(res)// [1,2,3]
console.log(arr1,arr2) // [] []
这是我的签名