Garry's Mod Wiki

table.SortByMember

  table.SortByMember( table tab, any memberKey, boolean ascending = false )

Description

Sorts a table by a named member.

Arguments

1 table tab
Table to sort.
2 any memberKey
The key used to identify the member.
3 boolean ascending = false
Whether or not the order should be ascending.

Example

Orders a table by a member and prints it.

local tab = { { Name = "Bill", Age = 13 }, { Name = "Jill", Age = 14 }, { Name = "Phil", Age = 8 } } table.SortByMember( tab, "Age" ) for _, v in ipairs( tab ) do print( v.Name ) end
Output: Jill Bill Phil