Table.find

From GiderosMobile

Available since: Gideros 2022.3
Class: table

Description

Within the given array-like table t, find the first occurrence of value, starting from index or the beginning if not provided. If the value is not found, nil is returned.

(any) = table.find(t,value,index)
A linear search algorithm is performed

Parameters

t: (table) source table
value: (any) value to find
index: (number) index to start the search at optional

Return values

Returns (any) the index of first occurence of value or nil if not found

Example

local t = {"a", "b", "c", "d", "e"}
print(table.find(t, "d")) --> 4
print(table.find(t, "z")) --> nil, because z is not in the table
print(table.find(t, "b", 3)) --> nil, because b appears before index 3