I am facing an issue with using an Array to store boilerplate objects that can be copied, modified, and added to another Array. The problem arises when the new Array takes ownership of the object, causing changes to persist in the original object.
For example:
var originals = [{ name: "One", value: 1 }, { name: "Two", value: 2 }, { name: "Three", value: 3 }];
var notOriginal = [];
notOriginal.push(originals[0]);
// This results in - notOriginal = [{ name: "One", value: 1 }];
notOriginal[0].name = "Uno";
// As a result - originals = [{ name: "Uno", value: 1 },...];
I want to ensure that the "originals" variable remains unchanged throughout this process.
Although I have searched extensively online and tried various solutions, I am still struggling to find a proper fix for this issue.
This behavior is particularly noticeable in VueJS when dealing with object manipulation within my data().