Returns a sorted array of the top level keys in a structure. Sorts using alphabetic or numeric sorting, and can sort based on the values of any structure element.
structSort(struct [, sortType, sortOrder, path, localeSensitive])
structSort(struct, callback)
→ returns array
struct.sort([sortType, sortOrder, path, localeSensitive])
text
numeric
text
textnocase
asc
asc
desc
false
function(key1, key2)
someStruct = {red=93,yellow=90,green=94};
result = structSort(someStruct, "numeric", "desc");
writeOutput( lcase(serializeJSON(result)) );
Expected Result: ["green", "red", "yellow"]
someStruct = {};
someStruct.scott = {age=26, department="General"};
someStruct.glan = {age=29, department="computer"};
someStruct.george = {age=31, department="Physical"};
result = structSort(someStruct, "textnocase", "asc", "department");
writeOutput( lcase(serializeJSON(result)) );
Expected Result: ["glan","scott","george"]
Compare values via dateCompare
birthdays = {
'Jim': '1982/12/5',
'Anne': '1968/9/13',
'Thomas': '1975/3/28'
};
sorted = structSort(birthdays,function(e1,e2) {
return dateCompare(e1,e2);
});
for(birthday in sorted) {
writeOutput(birthday&' ('&dateDiff('yyyy',birthdays[birthday],now())&'), ');
}
Expected Result: Anne (49), Thomas (42), Jim (35),
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.