배열에서 사용
let arr1 = [1,2,3];
let arr1 = [1,2,3];
let result = [0, ...arr1, ...arr2, 7,8,9];
//[0, 1, 2, 3, 1, 2, 3, 7, 8, 9]
객체에서의 사용
let user = {name : 'mike'}
let mike = {...user, age:30}
console.log(mike);
//{name: 'mike', age: 30}
let arr = [1,2,3];
let arr2 = [...arr];
console.log(arr2);
//(3) [1, 2, 3]
let user = {name:'Mike', age:30};
let user2 = {...user};
user2.name = 'tom';
console.log(user);
console.log(user2);
//{name: "Mike", age: 30}
//{name: "tom", age: 30}
활용
let user = {name : 'mike'};
let info = {age : 30};
let fe = ["js", "react"];
user = {
...user,
...info,
skills : [...fe]
};
console.log(user);
//{name: "mike", age: 30, skills: Array(2)}
//name: "mike"
//age: 30
//skills: Array(2)
//0: "js"
//1: "react"