ArraySort

Sorts array elements.

Method Signature

ArraySort(array=[assignablearray], sortType=[any], sortOrder=[string], localeSensitive=[boolean], callback=[function:Comparator])

Arguments

Argument
Type
Required
Description
Default

array

assignablearray

true

The array to sort

sortType

any

false

Options are text, numeric, or textnocase

textnocase

sortOrder

string

false

Options are asc or desc

asc

localeSensitive

boolean

false

Sort based on local rules

false

callback

function:Comparator

false

Function to sort by

Examples

Simple example for arraySort function

Uses the arraySort() function to get the sorted array and which sorted by type numeric

Run Example

someArray = [ 
	10,
	20,
	-99,
	46,
	50
];
arraySort( someArray, "numeric", "desc" );
writeOutput( JSONSerialize( someArray ) );

Result: [50,46,20,10,-99]

Simple example with member function

Run Example

Result: ["boxlang","adobe","RAILO","Boxlang","BOXLANG"]

Simple example with callback function

Uses the callback function

Run Example

Result: [{"NAME":"employeetest","AGE":"36"},{"NAME":"testemployee","AGE":"32"}]

Script member syntax: sort array of structs by multiple keys

Takes an array of structs and sorts by multiple different keys, similar to the way a query allows.

Run Example

Result: Sorts by active employees, then by their last name and finally by their first name

Additional Examples

Run Example

Last updated

Was this helpful?