Disconnect variables when doing variable = variable

javascript

#1

I didn’t really know exactly what to call this, but this is something that I need help with. Basically, I have a variable (say, variable A), and another variable (variable B). If A is equal to an array, and then I set B to A, by changing values in B (like B[0]++), I also change values in A. Is there a way that I can assign the values, and then make them disconnected from each other (so that I can edit B without affecting A).


#2

I actually found a solution to this, though, it isn’t very efficient. I am sure there is a better way to do this, but this is the way I found. Instead of directly assigning variable A to B, just assign the VALUES of A to B. This allows you to independently change variable B without affecting A.

This is just the solution I found. If you find another way, please let me know