11. Arrays and typed arrays
func run() -> Array:
var clues: Array[String] = ["key", "note"]
clues.append("watch")
clues[1] = "torn_note"
clues.erase("key")
return [clues, clues.size(), clues.has("watch")]The first index is 0. Check size before reading an index. Array[String] restricts entries to strings. append adds at the end; insert adds at an index; erase removes a matching value; remove_at removes by index.
func run() -> Array:
var original: Array = [{"id": "key"}]
var independent: Array = original.duplicate(true)
independent[0]["id"] = "note"
return [original[0]["id"], independent[0]["id"]]Arrays are shared by reference. Assigning an array to a second variable does not create an independent list. duplicate(true) copies nested arrays/dictionaries too; contained Godot objects and resources still need their own deliberate ownership/copy policy.
Other useful methods include find, sort, reverse, shuffle, slice, filter, map and reduce. Avoid removing entries from the same array you are walking forward through; collect removals, loop backwards, or build a filtered result.
