index() Function

Returns the array[index] if it is valid or else returns the default value.

Syntax

index( array, index, [default] )

array: (Any Type Array) A homogeneous array, whose indexed value is expected.

index: (Integer or Integer Array) The index or array of indices of the array.

default: (Any Type) The default value to be returned if the array or the index is invalid, such as if the array itself is empty or the index is < 1 or > array length.

Returns

Any Type

Notes

The type of the default value must be same as that of the elements in the array.

Examples

Retrieving a value at a single index:

index({10, 20, 30}, 2, 1) returns 20

Return the value of a field name within a CDT where the array is the PV and the index is the field name:

index(pv!person, "firstName", "") returns the value of the "firstName" field in a CDT of person with two fields (firstName and lastName)

Retrieving values at multiple indices:

index({10, 20, 30}, {1, 3}, 0) returns 10, 30

Retrieving values at repeated indices:

index({10, 20, 30}, {1, 1, 3}, 0) returns 10, 10, 30

Retrieving the value of a CDT field using the field name as the index argument:

index(topaginginfo(1, 10), "startIndex", 0) returns 1

See Also

property(): This function acts as an alias to the index() function especially when applied over custom data types.

Open in Github Built: Tue, May 17, 2022 (03:04:26 PM)

On This Page

FEEDBACK