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 ( Array base, int type, StringName class_name, Variant script )

Array

Array ( Array from )

Array

Array ( PackedByteArray from )

Array

Array ( PackedColorArray from )

Array

Array ( PackedFloat32Array from )

Array

Array ( PackedFloat64Array from )

Array

Array ( PackedInt32Array from )

Array

Array ( PackedInt64Array from )

Array

Array ( PackedStringArray from )

Array

Array ( PackedVector2Array from )

Array

Array ( PackedVector3Array from )

Methods

bool

all ( Callable method ) const

bool

any ( Callable method ) const

void

append ( Variant value )

void

append_array ( Array array )