From Xojo Documentation

Revision as of 18:50, 24 November 2020 by PLefebvre (talk | contribs) (Usage)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Arrays.FirstIndex() As Integer

New in 2020r2

Supported for all project types and targets.

Returns the index of the first element of the array.


result = array.FirstIndex

Part Type Description
result Integer The starting index of the array.
array Array of any data type The array whose first element number you want.


The FirstIndex function is used to determine the first element of an array. This is especially useful for writing code that loops through arrays so that you don't have to be aware of whether an array begins at 0 or 1 (they all begin at 0).

Arrays can have a maximum index value of 2,147,483,646.

Sample Code

This code loops through an array and replaces each occurrence of X in an array with Y.

For i As Integer = names.FirstIndex To names.LastIndex
If names(i) = "X" Then
names(i) = "Y"
End If

See Also

Var statement; Arrays concept, ParamArray keyword, Arrays.LastIndex method