Last Item in List | ARRAY_LAST

Syntax

ARRAY_LAST( [value], [default] = null )

Parameters

value
The array whose last item is being retrieved.

default
A default value if VALUE is not an array or has no items.

Return Value

The last item in VALUE if it is a non-empty array, or the provided DEFAULT otherwise.

Description

Gets the last item in an array. It is a shorthand for using ARRAY_GET with an index value of -1.

Examples

ARRAY_LAST([1, 2, 3]) # returns 3
ARRAY_LAST([]) # returns NULL
ARRAY_LAST(null) # returns NULL
ARRAY_LAST([], "DEFAULT") # returns "DEFAULT"
ARRAY_LAST(null, "DEFAULT") # returns "DEFAULT"