js深淺copy

...點copy是淺拷貝
var obj1 = [1,{a: 1}];
//var obj2 = Object.assign( {}, obj1);//淺copy
//var obj2 = JSON.parse(JSON.stringify(obj1));//深copy
var obj2 = [...obj1];//淺copy
obj2[1].a = 5;
obj1;
blog

相關文章
相關標籤/搜索