So we all know that if we have an array of simple values sorting that array according to those values in Coldfusion couldn’t be easier. Using the arraySort() function will handle sorting the array fairly effortlessly on the developer’s part. However, what if you have an array of objects. Each object in the array contains a value that you want to sort by. Here things get slightly more complicated as the arraySort() function will not work in this case. However, sorting the array is still fairly simple. Before getting into this, let’s take a quick look at an array containing a set of objects with index values that need to be sorted.
Build an array with objects
<cfset variables.model = structNew() /> <cfset variables.model.data = arrayNew(1) /> <cfset variables.model.data[1] = structNew() /> <cfset variables.model.data[1].Index = 2 /> <cfset variables.model.data[2] = structNew() /> <cfset variables.model.data[2].Index = 4 /> <cfset variables.model.data[3] = structNew() /> <cfset variables.model.data[3].Index = 1 /> <cfset variables.model.data[4] = structNew() /> <cfset variables.model.data[4].Index = 3 />
This produces the following visually:

Unordered Array of Objects
At Monserrate Monastery in Bogotá, Colombia.