table.KeyFromValue
From GMod Wiki
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: | |
BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=Table.KeyFromValue]Table.KeyFromValue [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Example
Description | Prints the index of "Cereals". |
---|---|
Used on | |
Code | local food = {"Milk", "Chocolate", "Cereals", "Bacon"} print(table.KeyFromValue(food, "Cereals")) |
Output | 3 |
Additional Notes
- The "value" parameter can be any data type, but must be the same data type within the table.
- The returned key might be of any type.