标签:code 添加 没有 一个 传参 let rip log obj
展开一个数组
let arr = [1,3,5,7,9];
console.log(...arr);
// 1 3 5 7 9
连接一个数组
let arr = [1,3,5,7,9];
let arr1 = [2,4,6,8,10]
console.log(...arr,...arr1);
// 1 3 5 7 9 2 4 6 8 10
给函数传参使用
function test(a, b, c) {
return a + b + c;
}
var args = [0, 1, 2];
test(...args);//3);
拷贝对象
{}
,即:{...obj}
.let obj = {
name:"hong",
age:18,
sex:‘男‘
}
let obj2 = {...obj}
obj2.name = ‘wang‘;
console.log(obj,obj2);
// { name: ‘hong‘, age: 18, sex: ‘男‘ }
// { name: ‘wang‘, age: 18, sex: ‘男‘ }
合并对象、数组
let obj = {
name:"hong",
age:18,
sex:‘男‘
}
console.log({...obj,name:‘wang‘,height:180});
// { name: ‘wang‘, age: 18, sex: ‘男‘, height: 180 }
let arr = [1,3,5,6];
let arr1 = [...arr,2,4,6,8]
console.log(arr1)
// [1, 3, 5, 6,2, 4, 6, 8]
合并的意思就是,有相同的属性,将值覆盖,没有的属性,添加
标签:code 添加 没有 一个 传参 let rip log obj
原文地址:https://www.cnblogs.com/hongzhiguo/p/14600180.html