- 将字符串转成数组
var str = 'abc'
console.log([...str]) //['a','b','c']
- 将集合转成数组
var set=new Set([1,2,3])
console.log([...set]) //[1, 2, 3]
- 两个数组的合并
var arr1=[1,2,3]
var arr2=[4,5,6]
console.log([...arr1,...arr2]) //[1, 2, 3, 4, 5, 6]
- 在函数中,用来代替arguments参数
function fn(...args){
console.log(args) //[1,2,3]
}
fn(1,2,3)
function fn(x,...y){
console.log(x)
console.log(y)
}
fn(4,5,6) //4 和 [5,6]
fn("a") //a 和 []
fn() //undefined 和 []
来源:CSDN
作者:还在挖路的脱发鬼
链接:https://blog.csdn.net/Lorraineyxy/article/details/104114843