Returns list with value inserted at the first position, shifting all other elements one to the right.
See also ListAppend, ListInsertAt, and ListSetAt.
ListPrepend(list, value [, delimiters ])
Any list.
Number or list being prepended.
Set of delimiters used in list.
When prepending an element to a list, ColdFusion needs to insert a delimiter. If delimiters contain more than one delimiter, ColdFusion defaults to the first delimiter in the string, or, (comma) if delimiters was omitted.
If you intend to use list functions on strings that are delimited by the conjunction ", " (comma-space), as is common in HTTP header strings such as the COOKIE header, we recommend that you specify delimiters to include both comma and space because ColdFusion Server does not skip white space.
<!--- This example shows ListPrepend ---> <!--- First, query to get some values for our list ---> <HTML> <HEAD> <TITLE>ListPrepend Example</TITLE> </HEAD> <H3>ListPrepend Example</H3> <!--- Find a list of users who wrote messages ---> <CFQUERY NAME="GetMessageUser" DATASOURCE="cfexpress"> SELECT Subject, Posted FROM Messages </CFQUERY> <CFSET temp = ValueList(GetMessageUser.Subject)> <!--- loop through the list and show it with ListGetAt ---> <H3>This is a list of <CFOUTPUT>#ListLen(temp)#</CFOUTPUT> subjects posted in messages.</H3> <CFLOOP FROM="1" TO="#ListLen(temp)#" INDEX="Counter"> <CFOUTPUT><LI>(#Counter#) SUBJECT: #ListGetAt(temp, Counter)#</ CFOUTPUT> </CFLOOP> <CFSET TempToo = ListPrepend(temp, "Applause for Express", ",")> <UL> <CFLOOP FROM="1" TO="#ListLen(temptoo)#" INDEX="Counter"> <CFOUTPUT><LI>(#Counter#) SUBJECT: #ListGetAt(temptoo, Counter)#</ CFOUTPUT> </CFLOOP> </UL> <P>Note that one new item "Applause for Express" has been prepended to the list, but has not been added to the database. </BODY> </HTML>