Type Function
Library table.*
Return value Number
Revision 2018.3238
Keywords table, array


Returns the integer index of an element within an array, or nil if the element is not in the array. The search goes through the length of the array as determined by #t whose value is undefined if there are holes.


This function can not be used to locate a child table/array within the array being searched.


table.indexOf( t, element )
t (required)

Array. The array to be searched.

element (required)

String or Number. The element to search for within array t.


local t = { 1, 3, 5, 7, 9, "a", "b" }
print( table.indexOf( t, 9 ) )    --> 5
print( table.indexOf( t, 3 ) )    --> 2
print( table.indexOf( t, "b" ) )  --> 7