Description

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.

Returns

List

Syntax

ListMap(list, function(item [,index, list]) [,delimiter, includeEmptyFields)

History

ColdFusion 11: Added this function.

Parameters

Parameter

Req/Opt

Default

Description

list Required   The input list.
function 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
initialValue Optional   Initial value which will be used for the reduce operation. The type is any.
delimter Optional comma (,) The list delimiter. The type is string.
includeEmptyFields Optional false Include empty values. The type is boolean.

Example

<cfscript>
       myList="Tokyo,Bangkok,Jakarta,Manila,Bangalore,Shanghai";
       myMap=ListMap(myList,function(item){ 
             return reverse(#item#); // Reverses each list item
             }
       );
       WriteOutput(myMap);
</cfscript>

Output

oykoT,kokgnaB,atrakaJ,alinaM,erolagnaB,iahgnahS

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy