参数扩展/展开 …args
收集剩余的参数,必须放在最后一个参数位置,
展开数组,简写,效果和直接把数组的内容写在这个一样
function show(a, b, ...args) {
console.log(a)
console.log(b)
console.log(args)
}
console.log(show(1, 2, 3, 4, 5)) //1,2,3,4,5
let arr1 = [1, 2, 3]
let arr2 = [4, 5, 6]
let arr3 = [...arr1, ...arr2]
console.log(arr3)//1,2,3,4,5,6
默认参数
function show2(a, b = 5, c = 8) {
console.log(a, b, c)
}
show2(88, 12) // 88,12,8