listPrepend

Inserts an element at the beginning of a list.

listPrepend(someList, value [, delimiters, includeEmptyFields]) → returns string

Member Function Syntax

someList.listPrepend( value [, delimiters, includeEmptyFields])

Argument Reference

list string
Required

A string list.

value string
Required

An element or list of elements.

delimiters string
Default: ,

Characters that separate list elements.

includeEmptyFields boolean
Default: false

CF 2018+ Set to true to insert blank values to the beginning of the list.
Values:
  • true
  • false

Examples
Sample code invoking the listPrepend function

CF 11+ Lucee 4.5+

seinfeldList = "Close Talker,Soup Nazi";
seinfeldList = seinfeldList.listPrepend("Puffy Shirt");
writeOutput(seinfeldList);

Expected Result: "Puffy Shirt,Close Talker,Soup Nazi"

someList = "1-2-3-4";
someList = listPrepend(someList,"0","-");
writeOutput(someList);

Expected Result: "0-1-2-3-4"

CF 2018+

someList = "Feb,Mar,Apr";
someList = listPrepend(someList, ",,Jan", ",", true);
writeOutput(someList);

Expected Result: ",,Jan,Feb,Mar,Apr"

CF 2018+

someList = "Feb,Mar,Apr";
someList = listPrepend(someList, ",,Jan,,", ",", false);
writeOutput(someList);

Expected Result: "Jan,Feb,Mar,Apr"

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub