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);

这篇博客介绍了JavaScript中的一些基本数组操作,包括数组的分割和连接。使用`push()`方法结合扩展运算符可以方便地合并数组。此外,还探讨了函数参数解析的用法,展示了如何使用剩余参数来捕获不确定数量的参数,以及如何在函数定义中指定多个普通参数和剩余参数。
1412

被折叠的 条评论
为什么被折叠?



