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])

arrayEach Argument Reference

array array
Required

callback
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+ Specifies whether the items can be executed in parallel

maxThreads numeric
Default: 20

Lucee 4.5+ 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;


Fork me on GitHub