first

Returns the first 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.first([alt]])

Arguments

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

Return value

First item in the list.

Example

This code shows an example using first():

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

Return value in JSON format

"January"