数组浅拷贝(ES6,JavaScript)— 用扩展运算符

// 扩展运算符 — 推荐
const arr = [1,2,3]
const copyArr = [...arr]

// ES5
var arr = [1, 2, 3]
var len = arr.length
var copyArr = []

for (var i = 0; i < len; i += 1) {
copyArr[i] = arr[i]
}

你可能感兴趣的:(数组浅拷贝(ES6,JavaScript)— 用扩展运算符)