Why does the array change?

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

Ok so I was just trying to make an array and when the user finished and clicked finished it would delete the selected item from the OptionButton. But for some reason, it removes the element from both arrays.

var array1 = ["Number one", "Number 2"]
var array2 = array1

func _ready():

But then It removes the element from array1 & array2

:bust_in_silhouette: Reply From: sry295

because Array and Dictionary are pointer-based data type (in Godot)
when you ‘array2 = array1’
array2 will point to the same array as array1
to separate it, you need to create the new array for array2 to point to

var array1 = ["Number one", "Number 2"]
var array2 = array1.duplicate()