Name
ArrayInsertAt
Synopsis
ArrayInsertAt(array, value, position
)
Inserts value
into the designated
array
at the specified
position
. Values having an index position
greater than the inserted data are shifted right by one. Using
ArrayInsertAt( )
increases the size of the array
by 1 and returns a value of True
upon successful
completion. Here’s an example of inserting an element into the
third position of a one-dimensional array called
Grades
:
<CFSET Grades = ArrayNew(1)> <CFSET Grades[1] = 95> <CFSET Grades[2] = 93> <CFSET Grades[3] = 87> <CFSET Grades[4] = 100> <CFSET Grades[5] = 74> <B>Original Array:</B><BR> <CFLOOP INDEX="Element" FROM="1" TO="#ArrayLen(Grades)#"> <CFOUTPUT>Grade #Element#: #Grades[Element]#<BR></CFOUTPUT> </CFLOOP> <P>Insert 65 into Element 3: <CFSET ArrayInsertAt(Grades, 3, 65)> <P><B>New Array</B><BR> <CFLOOP INDEX="Element" FROM="1" TO="#ArrayLen(Grades)#"> <CFOUTPUT>Grade #Element#: #Grades[Element]#<BR></CFOUTPUT> </CFLOOP>
Get Programming ColdFusion now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.