其他分享
首页 > 其他分享> > Spread Operator展开运算符(...)

Spread Operator展开运算符(...)

作者:互联网

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]
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 和 []
还在挖路的脱发鬼 发布了6 篇原创文章 · 获赞 0 · 访问量 204 私信 关注

标签:...,console,log,运算符,var,Spread,数组,Operator,fn
来源: https://blog.csdn.net/Lorraineyxy/article/details/104114843