Let's say I have this code:
local testtbl = {"foo", "bar", "baz"}
How do I get the index of an element? For example:
print(indexOf(testtbl, "bar")) -- 2
You need to iterate over the table with ipairs, like so:
ipairs
function indexOf(tbl, value) for i, v in ipairs(tbl) do if v == value then return i end end end
You need to iterate over the table with
ipairs, like so: