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

Function syntax

ArrayNew(dimension)

Parameters

Parameter

Description

dimension

Number of dimensions in new array: 1, 2, or 3

Example

<h3>ArrayNew Example</h3> 
<!--- Create 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> 
    <p>It has #ArrayLen(MyNewArray)# elements.</p> 
    <p>Contents: #ArrayToList(MyNewArray)#</p> 
<!--- The array has expanded dynamically to six elements with the use of ArraySet, 
    even though we only set three values. ---> 
</cfoutput>