Loop Over ColdFusion Structure

Just a quick reference on how to loop over a structure without knowing its keys. By the loop, you may also convert the structure

.

<cfset aaaa.ab1 = '111'>
<cfset aaaa.ab2 = '222'>
<cfset aaaa.ab3 = '333'>
<cfset aaaa.ab4 = '444'>

<cfset logcontent = "">
<cfloop list="#structKeyList(aaaa)#" index="key">
<cfoutput>
<cfset logcontent = logcontent & "(" & #key# & ": " & #aaaa[key]# & ")">
</cfoutput>
</cfloop>

<cfdump var="#aaaa#">

Leave a Reply

%d bloggers like this: