Sorts array elements.

arraySort(array, sortType [, sortOrder]) or arraySort(array, callback) → returns boolean

Member Function Syntax

someArray.sort(sortType [, sortOrder])

arraySort Argument Reference

array array

Name of an array

sortType string

numeric: sorts numbers
text: sorts text alphabetically, taking case into account
(also known as case-sensitive). All letters of one case
precede the first letter of the other case:
- aabzABZ, if sort_order = "asc" (ascending sort)
- ZBAzbaa, if sort_order = "desc" (descending sort)

textnocase: sorts text alphabetically, without regard to
case (also known as case-insensitive). A letter in varying
cases precedes the next letter:
- aAaBbBzzZ, in an ascending sort; preserves original
intra-letter order
- ZzzBbBaAa, in a descending sort; reverses original
intra-letter order
  • numeric
  • text
  • textnocase

sortOrder string
Default: asc

asc: ascending sort order. Default.
- aabzABZ or aAaBbBzzZ, depending on value of sort_type,
for letters
- from smaller to larger, for numbers

desc: descending sort order.
- ZBAzbaa or ZzzBbBaAa, depending on value of sort_type,
for letters
- from larger to smaller, for numbers
  • asc
  • desc

callback any

The callback function which take two elements of an array, Returns whether the first is less than (-1), equal to (0) or greater than (1) the second one (like as compare function).

Examples sample code invoking the arraySort function

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

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

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

CF 11+ Lucee 4.5+

SomeArray = ["COLDFUSION","coldfusion","adobe","LucEE","RAILO"];
writeOutput( serializeJSON(SomeArray) );

Expected Result: ["coldfusion","adobe","RAILO","LucEE","COLDFUSION"]

Uses the callback function

SomeArray = [
    {name="testemployee", age="32"},
    {name="employeetest", age="36"}
    function (e1, e2){
        return compare(,;
writeOutput( serializeJSON(SomeArray) );

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

Fork me on GitHub