arrayMap
Iterates over every entry of the array and calls the closure function to work on the element of the array. The returned value will be set at the same index in a new array and the new array will be returned
arrayMap(array, function(item [,index, array]){} [, parallel] [, maxThreads]) → returns array
Member Function Syntax
someArray.map(function(item [,index, array]){} [, parallel] [, maxThreads])
Argument Reference
array array Required
The input array
callback any Required
Closure or a function reference that will be called for each of the iteration.
Callback parameters:
-
value* any : The value for the current iteration -
index* numeric : The current index for the iteration -
array* array : A reference of the original array
parallel boolean
Default: false
false
Lucee 4.5+ true if the items can be executed in parallel
Values:
truefalse
maxThreads numeric
Default: 20
20
Lucee 4.5+ the maximum number of threads to use when parallel = true
Links more information about arrayMap
- Map, Reduce and other Higher Order Functions - A Primer for map, reduce, filter, and Higher Order Functions in general.
- ColdFusion 11: .map() and .reduce() - A look at the new .map() and .reduce() methods that each of array, struct and lists all have
- arrayMap(): a reverse CFML history - A history of custom implementations of map prior to CF11
Examples Sample code invoking the arrayMap function
complexData = [ {a: 4}, {a: 18}, {a: 51} ];
newArray = arrayMap( complexData, function(item){
return item.a;
});
writeDump(newArray); Expected Result: [4, 18, 51]
© 2012–present Foundeo, Inc. and the CFDocs contributors.
Licensed under the MIT License.
ColdFusion is a trademark of Adobe Systems Incorporated.
https://cfdocs.org/arraymap