arrayEach
Used to iterate over an array and run the function closure for each item in the array.
arrayEach(array, function(item, [index, [array]]){} [, parallel] [, maxThreads]) → returns void
Member Function Syntax
someArray.each(function(item, [index, [array]]){} [, parallel] [, maxThreads])
Argument Reference
array array Required
callback function 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+ CF 2021+ Specifies whether the items can be executed in parallel
maxThreads numeric
Default: 20
20
Lucee 4.5+ CF 2021+ The maximum number of threads to use when parallel = true
Links more information about arrayEach
- 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
Examples Sample code invoking the arrayEach function
letters = ["a","b","c","d"];
arrayEach(letters, function(element,index) {
writeOutput("#index#:#element#;");
}); Expected Result: 1:a;2:b;3:c;4:d;
a = ["a","b","c"];
a.each(function(element,index,array){
writeOutput("#index#:#element#;");
}); Expected Result: 1:a;2:b;3:c;
© 2012–present Foundeo, Inc. and the CFDocs contributors.
Licensed under the MIT License.
ColdFusion is a trademark of Adobe Systems Incorporated.
https://cfdocs.org/arrayeach