Quirrel4.41.0

types.Array.clear

Method on every array
clear(): any

Removes every element from the array.

Return value

This array, now empty.

Notes

Equivalent to resize(0), including that the backing storage is released once the array shrinks past its shrink threshold, not merely marked empty.

Example

examples/types/array/clear.nut
let a = [1, 2, 3];
let same = a.clear();
println("same == a:", same == a);   // clear() returns this array, now empty
println("a.len() =", a.len());
Output:
same == a: true
a.len() = 0

See also

resizeGrows or shrinks the array to size elements.
cloneMakes a shallow copy of the array.
arrayclass index