Array.clear() remove all elements of another array?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BookerY
var A = []
var B = [1,2,3]
A = B
print(A)
B.clear()
print(A)

the result is:
[1, 2, 3]

I really have no idea what’s going on here.
Why I cleared the B array then elements in A are gone??

:bust_in_silhouette: Reply From: Inces

Arrays and Dictionaries are passed via Reference. Introducing variable A like this makes it a reference to Array B, like a link to it. Any changes to A will be applied to variable it is linking its reference. The same things happen with Nodes. If You make variable A = get_node(“something”) and later You will do : A = get_node(“somethingdifferent”) - it will not change one node to the other, it will only change which Node will be referred when calling A.
If You want variable A to become new array, that is the same as var B, then You have to use duplicate() method :

var A = B.duplicate()