How to loop over an array in ColdFusion

cfloop - loop over an array

cflooparray.cfm


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cfloop tag example: how to loop over an array in coldfusion</title>
</head>

<body>
<h2 style="color:Crimson">cfloop Tag Example: Array</h2>

<cfset ColorArray=ArrayNew(1)>
<cfset ColorArray[1]="Red">
<cfset ColorArray[2]="Green">
<cfset ColorArray[3]="Yellow">
<cfset ColorArray[4]="Blue">

<cfdump var="#ColorArray#" label="ColorArray">
<br />

Loop Start[ColorArray]...<br />
<cfloop array="#ColorArray#" Index="Color">
 <cfoutput>
  <b>Current Color:</b> #Color#<br />
 </cfoutput>
</cfloop>
</body>
</html>





More ColdFusion examples