Description

Deletes an element from a specified position in 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).

Returns

True, on successful completion.

Category

Function syntax

ArrayDeleteAt(array, position)

See also

ArrayInsertAtFunctions for XML object management in Modifying a ColdFusion XML object in the Developing ColdFusion Applications

History

ColdFusion MX:

  • Changed behavior: This function can be used on XML objects.
  • Changed thrown exceptions: This function can throw the InvalidArrayIndexException error.

Parameters

Parameter

Description

array

Name of an array.

position

Array position.

Throws

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.

Example

<cfscript>
       myArray=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
       WriteOutput("Input array is: ");
       WriteOutput(serializeJSON(myArray) & "|");
       // Delete "Wednesday" at index 4
       ArrayDeleteAt(myArray,4); // Returns True since the fourth position is a valid position in the array
       WriteOutput("Array after deleting the member at position four is: ");
       WriteOutput(serializeJSON(myArray)); // Array with "Wednesday" deleted
</cfscript>

Output

Input array is: ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]|Array after deleting the member at position four is: ["Sunday","Monday","Tuesday","Thursday","Friday","Saturday"]

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy