Quirrel4.41.0

types.Array.pop

Method on every array
array.pop(): any

Removes and returns the last element.

Return value

The removed element.

Errors

Throws empty array when the array has no elements.

Notes

top reads the same element without removing it.

Example

examples/types/array/pop.nut
let a = [1, 2, 3];
println("a.pop() =", a.pop());   // removes and returns the last element
println("a.len() =", a.len());
try { [].pop() } catch (e) { println("[].pop() throws:", e); }
Output:
a.pop() = 3
a.len() = 2
[].pop() throws: empty array

See also

topReturns the last element without removing it.
appendAdds one or more values to the end of the array.
arrayclass index