Looping over ColdFusion Structure

The following are the reference and sample code on how to loop over a structure without knowing its keys.

 

<cfset testStruct = structnew() />

<cfset testStruct.key1 = "test1" /> 
<cfset testStruct.key2 = "test2" /> 
<cfset testStruct.key3 = "test3" /> 
 
<cfdump var="#testStruct#" /> 
 
<cfloop list="#structKeyList(testStruct)#" index="key"> 
<cfoutput> 
Key: #key#, Value: #testStruct[key]# 
</cfoutput> 
</cfloop>

Leave a Reply

google.com, pub-3772983857049267, DIRECT, f08c47fec0942fa0
%d bloggers like this: