View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > ArrayDeleteAt PreviousNext

ArrayDeleteAt

Deletes an element from an array.

When an element is deleted, ColdFusion recalculates index positions. For example, in an array that contains the months of the year, deleting the element at position 5 removes the entry for May. After this, to delete the entry for June, you would delete the element at position 5 (not 6).

True, on successful completion.

Array functions

ArrayDeleteAt(array, position)

ArrayInsertAt

ColdFusion MX:

Parameter

Description

array

Name of an array

position

Array position

If this function attempts to delete an element at position 0, or specifies a value for position that is greater than the size of array, this function throws an InvalidArrayIndexException error.

<h3>ArrayDeleteAt Example</h3><p>
<!--- create an array --->
<cfset DaysArray = ArrayNew(1)>
<!--- populate an element or two --->
<cfset DaysArray[1] = "Monday">
<cfset DaysArray[2] = "Tuesday">
<cfset DaysArray[3] = "Wednesday">
<!--- delete the second element --->
<p>Is the second element gone?: 
 <cfoutput>#ArrayDeleteAt(DaysArray,2)#</cfoutput>
<!--- the formerly third element, "Wednesday" is second element --->
<p>The second element is now: <cfoutput>#DaysArray[2]#</cfoutput>

Contents > CFML Reference > ColdFusion Functions > ArrayDeleteAt PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


brian_retke said on Apr 14, 2004 at 3:03 PM :
It is unclear to me whether this function can be used at all with 2 or 3 dimensional arrays. My experience suggests that it cannot, but it would be nice if the documentation included a note to that effect.
ASandstrom said on Apr 15, 2004 at 7:37 AM :
You can use ArrayDeleteAt with multi-dimensional arrays. However, it will delete an entire row of the array.

<h3>ArrayDeleteAt Example</h3><p>
<!--- create an array --->
<cfset DaysArray = ArrayNew(2)>
<!--- populate an element or two --->
<cfset DaysArray[1][1] = "Monday">
<cfset DaysArray[2][1] = "Tuesday">
<cfset DaysArray[3][1] = "Wednesday">
<cfset DaysArray[1][2] = "April 12">
<cfset DaysArray[2][2] = "April 13">
<cfset DaysArray[3][2] = "April 14">
<!--- delete the second element --->
<p>This is what the array looks like before delete:<br>
<cfoutput>
#DaysArray[1][1]#&nbsp;&nbsp;#DaysArray[1][2]#<br>
#DaysArray[2][1]#&nbsp;&nbsp;#DaysArray[2][2]#<br>
#DaysArray[3][1]#&nbsp;&nbsp;#DaysArray[3][2]#<br>
</cfoutput>

<cfoutput>
We delete this element of the array:<br>
#ArrayDeleteAt(DaysArray,2)#<br>
</cfoutput>
<!--- the formerly third element, "Wednesday" is second element --->
<p>This is what the array looks like after delete:<br>
<cfoutput>
#DaysArray[1][1]#&nbsp;&nbsp;#DaysArray[1][2]#<br>
#DaysArray[2][1]#&nbsp;&nbsp;#DaysArray[2][2]#<br>
</cfoutput>

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functia6.htm