1、分割数组
let arr = [1,2,3,4,5];
console.log(...arr);
2、连接数组
let arr = [1,2,3,4];
let arr2 = [5,6];
arr.push(...arr2);
console.log(arr);
其他方式
let arr = [1,2,3,4];
let arr2 = [5,6];
// arr.push(...arr2);
Array.prototype.push.apply(arr,arr2);
console.log(arr);
3、函数参数解析
function fn(...args){
console.log(args);
}
fn(1,2,3,4,5);
function fn(a,b,...args){
console.log(a,b,args);
}
fn(1,2,3,4,5,6);