Material Box

Material Box

WEB Design & Material Images

Godot - Add value to array

Godot

GDScript code example to add value to beginning or end of array.


Can add value to beginning of array using push_front() in GDScript.
push_front() also adds duplicate values.

As push_front() regenerates array indexes, it seems to be slower than push_back() and append().

var array = ["apple", "lemon"]
array.push_front("banana")

print(array)
# ["banana", "apple", "lemon"]

Can add value to end of array using push_back().
push_back() also adds duplicate values.

var array = ["apple", "lemon"]
array.push_back("banana")

print(array)
# ["apple", "lemon" , "banana"]

Can also use append() to add value to end of array.
append() also adds duplicate values.

var array = ["apple", "lemon"]
array.append("banana")

print(array)
# ["apple", "lemon" , "banana"]

Godot

TitleGodot - Add value to array

CategoryGodot

Created

Update

AuthorYousuke.U