I am trying to copy array in element of array and manipulate as per my need.
this.question?.labels.forEach((element) => {
element["options"] = [...this.question?.options]; // I've tried json.stringify() as well but not worked
element["options"].forEach(e => {
e.checked = this.question?.userAnswers.find(i => e.key === i.value && element.key === i.key) ? true : false;
});
});
I've used [...this.question?.options]
to get new copy of option every time. but it always saved last value of array in each element
https://stackblitz.com/edit/pass-array-by-value?file=src%2Fapp%2Fapp.component.ts