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

Lucee 4.5+ CF 2021+ Specifies whether the items can be executed in parallel

maxThreads numeric
Default: 20

Lucee 4.5+ CF 2021+ The maximum number of threads to use when parallel = true

Links more information about arrayEach

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;

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

Fork me on GitHub