Best way to clear an array?

Godot Version

Godot 4.2.1.stable

Question

In my code, I have encountered a situation where I have to remove all items from an array. I was wondering which is the more performant method to do this?

Method 1: clear()

var temp: Array = ["Hello", "World"]
temp.clear()

Method 2: =[ ]

var temp: Array = ["Hello", "World"]
temp = []

clear should be marginally faster, it’s not making a new empty array, only resizing an existing one to 0.

1 Like