Couldn't explain my question succinctly enough in the title, so I'm putting it here. It will actually be easier to show the code before asking my question:
array1 = []
array2 = [1,2,3]
array1 = array2
#=> array1 = [1,2,3]
array2.clear
#=> array1 = []
#=> array2 = []
Why does using the .clear method on the second array also clear what is in the first array? I guess what I'm asking is, once we set array1 = array2, why is array1 affected by the .clear we apply to array2? It seems that array1 = array2 will hold true for the duration of my script, is this right?
In order for array1 to remain unchanged once I do array2.clear, would I need to implement array1 = array2 a different way, such as using a for loop and .unshifting elements from array2 and .pushing them over to array1?
.cloneto create a true copy.