✓ Accepted answer
Lua's standard table library doesn't include a function already made that does this.
However, we can make one ourselves really easily using pairs.
function tablefind(tab, val)
for index, value in pairs(tab) do
if value == val then
return index
end
end
end
This searches through all index and value pairs in the table tab, and stops when it finds val, and returns the appropriate index.
In your example, tablefind(Test,"hello") would return 1.
This function upon not finding the value returns nil (which is convenient since nil cannot be a table index)
1 comment
Thanks.