table.SortByKey
From GMod Wiki
Function | |
Syntax |
table.SortByKey( Table Table, Boolean Descending ) Where is this used? |
Description: | |
Sorts a table by key. | |
Returns: | Table |
Part of Library: | Table |
Realm: | |
BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=Table.SortByKey]Table.SortByKey [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Example
Description | Sort the values of a Table by their key. |
---|---|
Used on | |
Code | local notsorted = {} notsorted[6] = "row 1" notsorted[3] = "row 2" notsorted[2] = "row 3" notsorted[4] = "row 4" notsorted[1] = "row 5" notsorted[5] = "row 6" local sorted = table.SortByKey(notsorted, false) PrintTable(sorted) -- This gets printed in the console: -- 1 = row 5 -- 2 = row 3 -- 3 = row 2 -- 4 = row 4 -- 5 = row 6 -- 6 = row 1 |
Output | prints the Table sorted into the console console. |