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) // [] []
标签:console,数组,js,let,arr2,arr1,清空,const,log 来源: https://www.cnblogs.com/zxcv123/p/16070175.html