arrayEach

Used to iterate over an array and run the function closure for each item in the array.

arrayEach(array array, function(item, [index, [array]]) closure, [boolean parallel], [number maxThreads]) → returns void

Member Function Syntax

someArray.each(function(item, [index, [array]]) closure, [boolean parallel], [number maxThreads])

Argument Reference for the arrayEach function

array

Required: Yes

closure

Required: Yes
function / closure with the signature: any function (any item, [numeric index], [array array]) - will be executed once per item in the array

parallel

Required: No
Default: false
Railo only option, true or false if the items can be executed in parallel

maxThreads

Required: No
Default: 20
Railo only option, the number of threads to use when parallel = true

Links more information about arrayEach

Examples sample code invoking the arrayEach function


Simple Example

letters = ["a","b","c","d"]; 
arrayEach(letters, function(element,index) 
 {
    writeOutput("#index#:#element#;");
});

Expected Result: 1:a;2:b;3:c;4:d;


Member Function Example

Array Loop -- array.Each()

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