数组展开运算符
console.log(...[1,2,3,4]) //1,2,3,4
//合并数组
const a = [1,2]
const b = [3,4,5]
conosle.log([...a,...b])
//将字符串转换成数组
let str = 'ljc'
console.log([...str])
剩余参数
const add = (a,b,...arg)=>{
console.log(arg) //[3,4,5]
}
add(1,2,3,4,5)
对象展开运算符
合并对象
const obj1 = {
name:'小明'
}
const obj2 = {
age:18
}
console.log({...obj1,...obj2}) //{name:'李嘉诚',age:18}
Set
Set是什么(集合)
//声明
const s = new Set()
Set参数
const s = new Set([1,2,3])
const s = new Set('hello')