Deleting elements from an array

Use the ArrayDeleteAt function to delete data from the array at a particular index, instead of setting the data value to zero or an empty string. If you remove data from an array, the array resizes dynamically, as the following example shows:

<!--- Create an array with three elements --->
<cfset firstname=ArrayNew(1)>
<cfset firstname[1]="Robert">
<cfset firstname[2]="Wanda">
<cfset firstname[3]="Jane"> <!--- Delete the second element from the array ---> <cfset temp=ArrayDeleteAt(firstname, 2)> <!--- Display the array length (2) and its two entries,
which are now "Robert" and "Jane" ---> <cfoutput> The array now has #ArrayLen(firstname)# indexes<br> The first entry is #firstname[1]#<br>
The second entry is #firstname[2]#<br>
</cfoutput>

The ArrayDeleteAt function removed the original second element and resized the array so that it has two entries, with the second element now being the original third element.


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

Version 7

 

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

Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00000954.htm