es6数组 - 扩展运算符

扩展运算符是三个点(...

console.log(...[1, 2, 3])
// 1 2 3
console.log(1, ...[2, 3, 4], 5)
// 1 2 3 4 5
[...document.querySelectorAll('div')]
// [<div>, <div>, <div>]

只有函数调用时,扩展运算符才可以放在圆括号中,否则会报错

(...[1, 2])
// Uncaught SyntaxError: Unexpected number

console.log((...[1, 2]))
// Uncaught SyntaxError: Unexpected number

console.log(...[1, 2])
// 1 2

  

 

posted @ 2020-03-24 16:16  banzhuxiang  阅读(129)  评论(0)    收藏  举报