ArrayMap()
Calls the given closure with every element in the given array.
The function returns an array that contains all values returned by the closure.
ArrayMap( array=array, closure=function, parallel=boolean, maxThreads=number );
Returns: Array
| Argument | Description | Default |
|---|---|---|
|
array
array,
required
|
edit
array to iterate |
|
|
closure
function,
required
|
edit
filter can be a function/closure that implements the following constructor [function(any value[, number index, array array]):any]. Alias: function, callback, udf |
|
|
parallel
boolean,
optional
|
edit
execute closures parallel |
|
|
maxThreads
number,
optional
|
edit
maximum number of threads executed, ignored when argument "parallel" is set to false Alias: maxThreadCount |
20 |
Examples
editModify an array and store it back into the array
Does not modify existing array, creates a new array and stores it to the assigned variable
aNames = ["Marcus","Sarah","Josefine"];
dump(aNames);
newNames1 = arrayMap(aNames,function(item,index,arr){
return {'name':item};
});
dump(newNames1);
//member function
newNames2 = aNames.map(function(item,index,arr){
return {'name':item};
});
dump(newNames2);
See also
- Arrays
- Collections
- Threads
- array.map()
- Complete Guide to Threading in Lucee
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)