Returns the index of the first element in the indicated array for which the given function returns something other than 0. Index counting starts at 1.

The <function> parameter must be included.

Syntax

ARRAY_FIRST_INDEX(<function>, <array>)

Parameters

ParameterDescriptionSupported input types
<function>A Lambda function used to check elements in the arrayAny Lambda function
<array>The array evaluated by the functionAny array

Return Type

ARRAY of the same type as the input array

Example

The following example returns the first value in the levels array that is greater than 2:

SELECT
	ARRAY_FIRST_INDEX(x -> x > 2, [ 1, 2, 3, 9 ]) AS levels;

Returns: 3