table.KeysFromValue

From GMod Wiki

Revision as of 17:13, 15 July 2011 by TheFreeman193 (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Function
Syntax table.KeysFromValue( Table table, Var value )
Where is this used?
Description:
Returns a table of indexes with the same value as value in the specified table.
Returns: Table Found indexes
Part of Library: Table
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Table.KeysFromValue]Table.KeysFromValue [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Example

DescriptionPrints a list of found indexes in the table.
Used onNewerShared.png
Code
local List = { Value1 = "15", Value2 = "12", "15", 15 }
PrintTable(table.KeysFromValue(List, "15"))
 
/*
Prints the following to the console:
1	=	1
2	=	Value1
 
Notice how it doesn't include the index of the last value in the table.
This is because it will only search for the value and datatype specified (A string in this case).
*/
OutputA table of indexes from the specified table.


Additional Notes

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox