Returning the index of a value in a Lua table

There is no way to do that without iterating.

If you find yourself needing to do this frequently, consider building an inverse index:

local index={}
for k,v in pairs(values) do
   index[v]=k
end
return index["a"]

Leave a Comment