How do I get the position of a value in a table

example
t = {“Help”, "Me, “Plz”}

Lets say I wanted to get the position of “Plz” how can I do that?



for k, v in pairs(YourTable) do
     if v == "Plz" then
     return k
end


The easy way to do it, but theres probably a better, cheaper way (can get expensive if you have a large table)

[editline]30th October 2010[/editline]

Another (one line) to do it is something like
table.foreach(YourTable, function(k,v) if v == “Plz” then return k end)

you only have one end in the 1st code. And you can only return stuff in functions.

What Feihc said packed in a neat function
[lua]
function table.KeyFromValue(t,v)

for k,_ in pairs(t) do

    if _ == v then

        return k
    end
end

end
[/lua]

FAIL.

[lua]
for k, v in pairs(YourTable) do
if v == “Plz” then
return k
end
end
[/lua]