When an object is put into another variable, it is copied by reference
. This means if the original object changes, the referenced values will change too.
|
|
As shown in example above, if copied by reference
, removing an element in one array will result in removal in another variable.
So these values must be deeply copied, which means values must be copied by value not reference.
There are several ways to do this, but I solved this with a simple solution (This is not the most efficient one. It only shows how to make a deeply copied array)
|
|
I did this and somehow it worked, but I’m not sure it this is right way to do it.
Many people suggests usng the JSON method:
Here are more discussions about it.