For the complete documentation index, see llms.txt. This page is also available as Markdown.

StructSort

Sorts a struct according to the specified arguments and returns an array of struct keys

Method Signature

StructSort(struct=[structloose], sortType=[any], sortOrder=[string], path=[string], callback=[function:Comparator])

Arguments

Argument
Type
Required
Description
Default

struct

struct

true

The struct to sort

sortType

any

false

An optional sort type to apply to that type - if a callback is given in this position it will be used as that argument

text

sortOrder

string

false

The sort order applicable to the sortType argument

asc

path

string

false

An optional key path used to sort by a nested value within each struct entry (e.g. "address.city").

callback

function:Comparator

false

An optional callback to use as the sorting function. You can alternatively pass a Java Comparator.

Examples

Numeric sorting

someStruct = { 
	RED : 93,
	YELLOW : 90,
	GREEN : 94
};
result = structSort( someStruct, "numeric", "desc" );
writeOutput( lcase( JSONSerialize( result ) ) );

Result: ["green", "red", "yellow"]

Sort by subelement

Result: ["glan","scott","george"]

Date sorting using callback

Compare values via dateCompare

Result: Anne (49), Thomas (42), Jim (35),

Additional Examples

Last updated

Was this helpful?