table.KeyFromValue

From GMod Wiki

Jump to: navigation, search
Function
Syntax table.KeyFromValue( Table table, Var value )
Where is this used?
Description:
Returns the value's index in the specified table, returns nothing if the value wasn't found.
Returns: Var key
Part of Library: table
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Table.KeyFromValue]Table.KeyFromValue [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Example

DescriptionPrints the index of "Cereals".
Used onNewerShared.png
Code
local food = {"Milk", "Chocolate", "Cereals", "Bacon"}
 
print(table.KeyFromValue(food, "Cereals"))
Output3


Additional Notes

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox