need help for remove element array

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SMaiLubis

i need help for remove element array
i have script:

var a = ["a", "b", "c", "d", "e"]

func _on_Button_pressed():
var b = a
b.remove(1)
print(a)
print(b)

output is
[a, c, d, e]
[a, c, d, e]

what i want is
[a, b, c, d, e]
[a, c, d, e]

everytime i remove element of b, element of a is removed too
can anyone help me?

:bust_in_silhouette: Reply From: volzhs

var b = a is just getting a reference of a
you need to copy of a

var b = [] + a

This code works as you expected, which creates a new array and append a

oh… Thank you very much

SMaiLubis | 2019-03-13 12:45