table.SortByMember

From Garry's Mod
Jump to: navigation, search
 table.SortByMember( )

Contents

Description

Sorts a table by a named member

Arguments

table tab

Table to sort

Arguments

any memberKey

The key used to identify the member

Arguments

boolean ascending=false

Whether or not the order should be ascending

Examples

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 k, v in ipairs(tab) do
    print(v.Name)
end

Output:

Jill

Bill

Phil
Personal tools
Navigation