How To The Write `arrayMap( )` Function In ColdFusion?
Description:-
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.
arrayMap( array, function( item [ ,index, array ] ){ } [ , parallel ] [ , maxThreadCount ] );
Attributes:-
array:-
This is a required argument, the name of the array object.
filter/callback:-
This is a required argument, The inline function is executed for each element in the array. Returns true if the array element has to be included in the resultant array. The callback function accepts these Callback parameters:-value:-
any: The value for the current iteration.index (optional):-
numeric: The current index for the iteration.array (optional):-
array: a copy of the original array. but the changes to this array will not be reflected in the original array.
parallel:-
This is a non-required attribute, the default value is false
, set as true
if the items can be executed in parallel.
maxThreadsCount:-
This is a non-required attribute, the default value is 20
.
Example:-
complexData = [ { a : 4 }, { a : 18 }, { a : 51 } ];
newArray = arrayMap( complexData, function( item ){
return item.a;
} );
writeDump( newArray );
Result:-
[ 4, 18, 51 ];