SortedPairs
From Garry's Mod
Contents |
Description
This function can be used in a for loop instead of pairs. It sorts all keys alphabetically.
For sorting by specific value member, use SortedPairsByMemberValue.
For sorting by value, use SortedPairsByValue.
Arguments
table table
The table to sort
Arguments
boolean desc=false
Reverse the sorting order
Returns
Iterator function
Returns
The table being iterated over
Examples
Example
Example of usage.
for id, text in SortedPairs( { "e", "b", "d", "c", "a" } ) do print(id, text) end print( "---" ) for id, text in SortedPairs( { e = 1, b = 2, d = 3, c = 4, a = 5 } ) do print(id, text) end
Output:
1 e 2 b 3 d 4 c 5 a --- a 5 b 2 c 4 d 3 e 1