ArrayMap
Iterates over every entry of the array and calls the closure function to work on the element of the array.
The returned value will be set at the same index in a new array and the new array will be returned
Method Signature
ArrayMap(array=[array], callback=[function:Function], parallel=[boolean], maxThreads=[integer])
Arguments
Argument
Type
Required
Description
Default
array
array
true
The array to reduce
callback
function:Function
true
The function to invoke for each item. The function will be passed 3 arguments: the current item, and the current index, and the original array. You can alternatively pass a Java Function which will only receive the 1st arg. The function should return the value that will be set at the same index in the new array.
parallel
boolean
false
false
maxThreads
integer
false
Examples
Script Syntax
complexData = [
{
A : 4
},
{
A : 18
},
{
A : 51
}
];
newArray = arrayMap( complexData, ( Any item ) => {
return item.A;
} );
writeDump( newArray );
Result: [4, 18, 51]
Additional Examples
aNames = [
"Marcus",
"Sarah",
"Josefine"
];
dump( aNames );
newNames1 = arrayMap( aNames, ( Any item, Any index, Any arr ) => {
return {
"name" : item
};
} );
dump( newNames1 );
// member function
newNames2 = aNames.map( ( Any item, Any index, Any arr ) => {
return {
"name" : item
};
} );
dump( newNames2 );
Related
Last updated
Was this helpful?