Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Array

A built-in data structure that holds a sequence of elements.

Description

An array data structure that can contain a sequence of elements of any type. Elements are accessed by a numerical index starting at 0. Negative indices are used to count from the back (-1 is the last element, -2 is the second to last, etc.).

Example:

var array = ["One", 2, 3, "Four"]
print(array[0]) # One.
print(array[2]) # 3.
print(array[-1]) # Four.
array[2] = "Three"
print(array[-2]) # Three.

Arrays can be concatenated using the + operator:

var array1 = ["One", 2]
var array2 = [3, "Four"]
print(array1 + array2) # ["One", 2, 3, "Four"]

Note: Arrays are always passed by reference. To get a copy of an array that can be modified independently of the original array, use duplicate.

Note: Erasing elements while iterating over arrays is not supported and will result in unpredictable behavior.

Note

There are notable differences when using this API with C#. See C# API differences to GDScript for more information.

Constructors

Array

Array()

Array

Array(base: Array, type: int, class_name: StringName, script: Variant)

Array

Array(from: Array)

Array

Array(from: PackedByteArray)

Array

Array(from: PackedColorArray)

Array

Array(from: PackedFloat32Array)

Array

Array(from: PackedFloat64Array)

Array

Array(from: PackedInt32Array)

Array

Array(from: PackedInt64Array)

Array

Array(from: PackedStringArray)

Array

Array(from: PackedVector2Array)

Array

Array(from: PackedVector3Array)

Methods

bool

all(method: Callable) const

bool

any(method: Callable) const

void

append(value: Variant)

void

append_array(array: Array)

void

assign(array: Array)

Variant

back()