User Guide Cancel

ListDeleteAt

 

Description

Deletes an element from a list.

Returns

A copy of the list, without the specified element.

Category

List functions

Function syntax

ListDeleteAt(list, position [, delimiters ])
ListDeleteAt(list, position [, delimiters, includeEmptyValues ])
ListDeleteAt(list, position [, delimiters ]) ListDeleteAt(list, position [, delimiters, includeEmptyValues ])
ListDeleteAt(list, position [, delimiters ]) 
ListDeleteAt(list, position [, delimiters, includeEmptyValues ])

See also

ListGetAtListSetAtListLenLists in Data types- Developing guide in the Developing ColdFusion Applications

Parameters

Parameter

Description

list

A list or a variable that contains one.

position

A positive integer or a variable that contains one. Position at which to delete element. The first list position is 1.

delimiters

A string or a variable that contains one. Characters that separate list elements. The default value is comma. If this parameter contains more than one character, ColdFusion processes each occurrence of each character as a delimiter.

includeEmptyValues

If includeEmptyValues is set to false, the list will contain only nonempty elements and the element would be deleted at the specified position.

Usage

To use this and other functions with the default delimiter (comma), you can code as follows:

<cfset temp2 = ListDeleteAt(temp, "3")>
<cfset temp2 = ListDeleteAt(temp, "3")>
<cfset temp2 = ListDeleteAt(temp, "3")>

To specify another delimiter, you code as follows:

<cfset temp2 = ListDeleteAt(temp, "3", ";")>
<cfset temp2 = ListDeleteAt(temp, "3", ";")>
<cfset temp2 = ListDeleteAt(temp, "3", ";")>

ColdFusion ignores empty list elements; thus, the list "a,b,c,,,d" has four elements.

Example

<cfscript>
myList="Tokyo,Bangkok,Jakarta,Manila,Bangalore,Shanghai";
WriteOutput(ListDeleteAt(myList,3) & " * "); //Deletes Jakarta at index 3
mySecondList="London,Paris|Sau Paulo,Santiago,Buenos Aires|New York,Montreal,Seattle|Tokyo,Shanghai";
WriteOutput(ListDeleteAt(mySecondList,3,"|")); //Deletes index 3 using custom delimiter
</cfscript>
<cfscript> myList="Tokyo,Bangkok,Jakarta,Manila,Bangalore,Shanghai"; WriteOutput(ListDeleteAt(myList,3) & " * "); //Deletes Jakarta at index 3 mySecondList="London,Paris|Sau Paulo,Santiago,Buenos Aires|New York,Montreal,Seattle|Tokyo,Shanghai"; WriteOutput(ListDeleteAt(mySecondList,3,"|")); //Deletes index 3 using custom delimiter </cfscript>
<cfscript>
       myList="Tokyo,Bangkok,Jakarta,Manila,Bangalore,Shanghai";
       WriteOutput(ListDeleteAt(myList,3) & " * "); //Deletes Jakarta at index 3
       mySecondList="London,Paris|Sau Paulo,Santiago,Buenos Aires|New York,Montreal,Seattle|Tokyo,Shanghai";
       WriteOutput(ListDeleteAt(mySecondList,3,"|")); //Deletes index 3 using custom delimiter
</cfscript>

Output

Tokyo,Bangkok,Manila,Bangalore,Shanghai * London,Paris|Sau Paulo,Santiago,Buenos Aires|Tokyo,Shanghai

Get help faster and easier

New user?