User Guide

386 Chapter 3: ColdFusion Functions
ArrayNew
Description
Creates an array of 1–3 dimensions. Index array elements with square brackets: [ ].
ColdFusion arrays expand dynamically as data is added.
Returns
An array
Category
Array functions
Function syntax
ArrayNew(dimension)
Parameters
Example
<h3>ArrayNew Example</h3>
<!--- Make an array --->
<cfset MyNewArray = ArrayNew(1)>
<!--- ArrayToList does not function properly if the Array is not initialized
with
ArraySet --->
<cfset temp = ArraySet(MyNewArray, 1,6, "")>
<!--- set some elements --->
<cfset MyNewArray[1] = "Sample Value">
<cfset MyNewArray[3] = "43">
<cfset MyNewArray[6] = "Another Value">
<!--- is it an array? --->
<cfoutput>
<p>Is this an array? #IsArray(MyNewArray)#
<p>It has #ArrayLen(MyNewArray)# elements.
<p>Contents: #ArrayToList(MyNewArray)#
<!--- the array has expanded dynamically to six elements with the use of
ArraySet,
even though we only set three values --->
</cfoutput>
Parameter Description
dimension Number of dimensions in new array.
1, 2, or 3