我有一个输入的对象数组.让我们来称呼它content.
尝试深度复制时,它仍然具有对前一个数组的引用.
我需要复制该输入数组,并更改重复部分的一个属性.
很久以来我尝试了不成功的不同方法.
ES6方式:
public duplicateArray() {
arr = [...this.content]
arr.map((x) => {x.status = DEFAULT});
return this.content.concat(arr);
}
Run Code Online (Sandbox Code Playgroud)
该slice方式:
public duplicateArray() {
arr = this.content.slice(0);
arr.map((x) => {x.status = DEFAULT});
return this.content.concat(arr);
}
Run Code Online (Sandbox Code Playgroud)
在这两个数组中,所有对象都有status: 'Default'.
在Angular 2中深度复制数组的最佳方法是什么?