es6深层次数组深拷贝
let arr = [
{
label: '1',
children: [1, 2]
}
]
let a = [{...arr[0]}]
a[0].children = []
console.log(arr[0].children)// 结果是[1,2]
let arr = [
{
label: '1',
children: [1, 2]
}
]
let a = [...arr[0]]
a[0].children = []
console.log(arr[0].children)// 结果是[]
//Deep Clone
obj1={a:0,b:{c:0}};
let obj3=JSON.parse(JSON.stringify(obj1));
obj1.a=4;
obj1.b.c=4;
console.log(JSON.stringify(obj3)); //{a:0,b:{c:0}}
锲而舍之,朽木不折;锲而不舍,金石可镂。