listMap

Iterates over every entry of the List and calls the closure function to work on the item of the list. The returned value will be set at the same index in a new list and the new list will be returned.

listMap(list, function(item [,index, list]) [,delimiter, includeEmptyFields) → returns string

Argument Reference

list string
Required

The input list.

function any
Required

Closure or a function reference that will be called for each of the iteration. The arguments passed to the callback are

item: value
index : current index for the iteration
list : reference of the original list

Callback parameters:

  • item*string : value
  • index*numeric : current index for the iteration
  • list*string : reference of the original list

intialValue any

Initial value which will be used for the reduce operation.

delimiter string
Default: ,

The list delimiter.

includeEmptyFields boolean
Default: false

Include empty values

Links more information about listMap

Examples
Sample code invoking the listMap function

Rainbow = "Whero, Karaka, Kowhai, Kakariki, Kikorangi, Tawatawa, Mawhero";
externalList = "";
reverseRainbow = listMap( rainbow, function(v,i,l) {
	var newValue = "#i#:#v.reverse()#";
	externalList = externalList.listAppend(newValue);
	return newValue;
});
writeDump([{rainbow=rainbow},{reverseRainbow=reverseRainbow},{externalList=externalList}]);

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

Fork me on GitHub