...
扩展运算符能将 数组 转换为逗号分隔的 序列参数。
const person = ['易烊千玺', '王俊凯', '王源']; let test = (...args) => { console.log(args) } function test() { console.log(arguments); } test(...person)// test('易烊千玺', '王俊凯', '王源')
数组的合并
const target1 = []; const target2 = []; // ES5 const result = target1.concat(target2) // ES6 const result = [...target1, ...targer2]
数组克隆(若子项没有引用则深拷贝,若有则浅拷贝)
const arr = ['E','G','M']; const copyArr = [...arr];
将伪数组转为真正的数组
const divs = document.querySelectorAll('div'); const el = [...divs];