In order to understand the scenario (in case your unfamiliar with it), following is an example showing a value in an object that we want to stay as “4”:
Now for the solution! Here is how to overcome the scenario quite easily:
You will notice the use of a function called “deepCopy”. This is a function you must include in your code to use as follows:
And thats how you do it! For the life of me, I cannot remember where I originally grabbed this nice little function from, but please advise if you know!