table.indexOf()

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

Overview

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

Syntax

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

Array. The array to be searched.

element (required)

Any. The element in the array.

Example

local t = {1,3,5,7,9}
print( table.indexOf( t, 9 ) ) -- output: 5