User Guide Cancel

ListGetAt

 

Description

Gets a list element at a specified position.

Returns

Value of the list element at position position.

History

ColdFusion (2018 release): Changed Parameter name includeEmptyValues to includeEmptyFields.

Category

List functions

Function syntax

ListGetAt(list, position [, delimiter, includeEmptyFields])
ListGetAt(list, position [, delimiter, includeEmptyFields])
ListGetAt(list, position [, delimiter,  includeEmptyFields])

See also

ListFirstListLastListQualifyListSetAtLists 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 get the element. The first list position is 1.

delimiter

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.

includeEmptyFields

Optional. Set to yes to include empty values.

Usage

If you use list functions on strings that are delimited by a delimiter character and a space, a returned list element might contain a leading space; you use the trim function to remove such spaces from a returned element. For example, consider this list:

<cfset myList = "one hundred, two hundred, three hundred">
<cfset myList = "one hundred, two hundred, three hundred">
<cfset myList = "one hundred, two hundred, three hundred">

To get a value from this list, use the trim function to remove the space before the returned value:

<cfset MyValue = #trim(listGetAt(myList, 2))#>
<cfset MyValue = #trim(listGetAt(myList, 2))#>
<cfset MyValue = #trim(listGetAt(myList, 2))#>

With this usage, MyValue = "two hundred", not " two hundred", and spaces within a list element are preserved. 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(ListGetAt(myList,4)); // Returns Manila
</cfscript>
<cfscript> myList="Tokyo,Bangkok,Jakarta,Manila,Bangalore,Shanghai"; WriteOutput(ListGetAt(myList,4)); // Returns Manila </cfscript>
<cfscript>
       myList="Tokyo,Bangkok,Jakarta,Manila,Bangalore,Shanghai";
       WriteOutput(ListGetAt(myList,4)); // Returns Manila
</cfscript>

Output

Manila

Get help faster and easier

New user?