ArrayMap
Takes an array and executes the function declared in the Mapper field for each of its elements, returning a new array containing the results. The output array preserves the same order and length as the input array.
Reference
Parameters
array
The array whose elements the mapper will be applied to.
Component data2-core-types@Getter
mapper
The function applied to each element. It expects a Function component, with an Arguments field declaring a key to reference each item during iteration (e.g. number). The key can then be used inside the function body via a Reference component, which dynamically resolves to the value of the current element at each iteration.
Component data2-core-functions@Function
Example
Input
[1, 2, 3, 4, 5]
Arguments key: number
Mapper:
- Function: Multiply
- Components:
- Reference:
number 2
- Reference:
- Components:
Output:
[2, 4, 6, 8, 10]
Note: The output array will always have the same number of elements as the input array. Each position in the output corresponds directly to the result of the function applied to the element at the same position in the input.