var arr=[1,2,3,4,5,6];
console.log(...arr);// 1 2 3 4 5 6
2.复制(浅拷贝)
数组的复制
var arr1=[1,2,3,4,[5]];
var arr2=[...arr1];
arr1[0]=10;
arr1 [4] [0]=100;
console.log(arr1);
console.log(arr2);
对象的复制
var obj1={name:"张三",age:18,person:{name:"李四"}};
var obj2={...obj1};
obj1.age=20;//深拷贝
obj1.person.name="王五" //浅拷贝
console.log(obj1);
console.log(obj2);
合并
数组的合并
var arr3=[1,2,3,4]
var arr4=[5,6,7]
var arr5=[...arr3,...arr4];
console.log(arr5);//[1,2,3,4,5,6,7]
对象的合并
var obj3={name="张三"}
var obj4={age:18}
var obj5={...obj3,...obj4}
console.log(obj5);
字符串改为数组
var myArr=[...'hello'];
console.log(myArr);//["h","e","l","l","o"]