Sorts array elements.
arraySort(array, sortType [, sortOrder [, localeSensitive ]])
or
arraySort(array, callback)
→ returns boolean
someArray.sort(sortType [, sortOrder, localeSensitive ])
numeric
text
textnocase
asc
asc
desc
function(element1, element2)
. Returns whether the first is less than (-1), equal to (0) or greater than (1) the second one (like the compare functions).
false
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"];
someArray.sort("text","desc");
writeOutput( serializeJSON(someArray) );
Expected Result: ["coldfusion","adobe","RAILO","LucEE","COLDFUSION"]
Uses the callback function
someArray = [
{name="testemployee", age="32"},
{name="employeetest", age="36"}
];
arraySort(
someArray,
function (e1, e2){
return compare(e1.name, e2.name);
}
);
writeOutput( serializeJSON(someArray) );
Expected Result: [{"NAME":"employeetest","AGE":"36"},{"NAME":"testemployee","AGE":"32"}]
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.