Table GetValue

[lua]function table.GetValue(t1,val)
for k,v in pairs(t1) do
if v == val then
return k
end
end
return false
end[/lua]

I was bored.

It’s more table.GetKeyByValue.

or table.FindValue

maybe I should release some helper functions too, I’ve accumulated quite some useful ones :slight_smile:

Your function is also not recursive. Tables held in t1 would not be searched.

utilx Thread

Oh and nice CP from Overv’s already existing function.

thanks stone, posted some

That would defeat the purpose.

How would it being recursive defeat the purpose of it finding a value?
If I wanted to know if a value was in a table that contained multiple items including another table, and ran the command as it’s listed in the OP… it would return false.
The function would be useless in that respect.
The item may be there…the function would never know.

The function returns an index in the table not a value.

Ah, thanks TheBigCheese.
I’d gotten this mixed up with ULib’s find value function.

It was actually a modified version of table.HasValue. Just never seen overv’s.