last

Returns the last item in the list. A lookup_err() is raised when this function is used on an empty list unless a default value is given, in which case the given value will be returned.

ThingsDB uses lazy-evaluation of function arguments. For this reason the default value might be a function call or code block which will only be evaluated when the list is empty.

This function does not generate a change.

Function

array.last([alt]])

Arguments

Argument Type Description
alt any (optional) Alternative value which is returned when the list is empty.

Return value

Last item in the list.

Example

This code shows an example using last():

["January", "February", "March", "April"].last();

Return value in JSON format

"April"