赞
踩
当函数或者其他需要使用参数的地方进行传参时,但是不知道具体有几个参数,就可以使用…来代表任意个参数。
function print(...values){
console.log(values);
}
print(1); //1
print(1,2,3,'aaaa',4); //[1,2,3,'aaaa',4]
当需要读取对象或数组中的元素或属性时,可以通过…来将其展开
而需要给数组或对象进行赋值时,也可以通过…来进行赋值
//将数组展开
let arr = [...[1,2,2,'a'],5];
console.log(arr); //[1, 2, 2, "a", 5]
//将一个对象展开
let person = {
name:'simon',
age: 24,
}
let simon = {person,job:'programmer'};
console.log(simon); //{person: {name: "simon", age: 24}, job: "programmer"}
let simoner = {...person,job:'student'}
console.log(simmoner); //{name: "simon", age: 24, job: "student"}
let arr, subArr;
//解构赋值
[a, ...subArr] =[1,2,3,4,5];
console.log(a); //1
console.log(subArr); //[2,3,4,5]
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。