I have an array of structs in ColdFusion. I\'d like to sort this array based on one of the attributes in the structs. How can I achieve this? I\'ve found the StructSort fun
It's actually even easier with the new CF Closure support.
Here's an example I worked on today where I wanted to sort an array of structs by a date stored in the struct. I was sorting in descending order.
ArraySort(yourArrayOfStructs, function(a,b) {
if ( DateCompare(a.struct_date, b.struct_date) == -1 ) {
return true;
} else {
return false;
}
});
I can't take total credit as I adapted this from Ray Camden's on Closures from 2012.