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.

Returns: array

Usage

ArrayMap( array, closure [, parallel [, maxThreads ] ] )

Arguments

Argument Description Default
array
(array, required)

array to iterate

closure
(function, required)

filter can be a function/closure that implements the following constructor [function(any value[, number index, array array]):any].

parallel
(boolean, optional)

execute closures parallel

maxThreads
(number, optional)

maximum number of threads executed, ignored when argument "parallel" is set to false

20

Examples

Modify 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