1-There are a couple of different ways you can copy an object.
The easiest way to copy something is via something called a spread.
A spread is a three dot operator and it's used for taking every single item in a object and spreading it into a new object.
const person3 = { …person1 };
2-There is another way to do this
const person3 = Object.assign({}, person1);
3- One thing to do note is that the spread operator only goes one level deep.
const person1 = {
first: "wes",
last: "bos",
clothing: {
shirts: 10,
pants: 2
}
};
const person3 = { …person1 };
console.log(person3);
Ex– arr1 =[1,2,3,4];
arr2 = [6,7,8];
let arr3 = […arr1, …arr2];
console.log(arr3);
output:–- [1, 2, 3, 4, 6, 7, 8]
give me result [0,1,2,3,4,6,7,8,9];
then
let arr4 = [0, …arr1, …arr2, 9];
console.log(arr4);