扩展运算符
spread扩展运算符
1.概念
扩展运算符(spread)也是三个点(...)。它好比 rest 参数的逆运算,将一个数组转为用逗号分隔的参数序列,对数组进行解包。
2.应用
(1)数组的合并
const arr1 = [1, 2, 3] const arr2 = ['a', 'b', 'c'] const arr3 = [...arr1, ...arr2] console.log(arr3) //[1,2,3,'a','b','c']
(2)数组的克隆(深拷贝)
const arr4=['one','two','three'] const arr5=[...arr4] arr5[1]='qq' console.log(arr5) //['one','qq','three'] console.log(arr4) //['one','two','three']

浙公网安备 33010602011771号