ES 6 数组的扩展
扩展运算符(spread)是三个点(...)。它好比rest参数的逆运算,将一个数组转为用逗号分隔的参数序列。
console.log(...[1, 2, 3]) // 1 2 3
console.log(1, ...[2, 3, 4], 5) // 1 2 3 4 5
//该运算符主要用于函数调用
function add(x, y) {
return x + y
}
const numbers = [4, 38]
add(...numbers) // 42
扩展运算符的应用
1..
原创
2021-04-19 15:37:37 ·
120 阅读 ·
0 评论