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

.

<br />
&lt;cfset aaaa.ab1 = '111'&gt;<br />
&lt;cfset aaaa.ab2 = '222'&gt;<br />
&lt;cfset aaaa.ab3 = '333'&gt;<br />
&lt;cfset aaaa.ab4 = '444'&gt;</p>
<p>&lt;cfset logcontent = &quot;&quot;&gt;<br />
&lt;cfloop list=&quot;#structKeyList(aaaa)#&quot; index=&quot;key&quot;&gt;<br />
&lt;cfoutput&gt;<br />
&lt;cfset logcontent = logcontent &amp; &quot;(&quot; &amp; #key# &amp; &quot;: &quot; &amp; #aaaa[key]# &amp; &quot;)&quot;&gt;<br />
&lt;/cfoutput&gt;<br />
&lt;/cfloop&gt;</p>
<p>&lt;cfdump var=&quot;#aaaa#&quot;&gt;<br />

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: