Array Map
This node transforms every item in an array into a new format using a script.
The Array Map node projects data from one shape to another.
The Array Map node iterates over an input array and creates a new array where each item is the result of a transformation function. This is commonly used to extract specific fields, rename properties, or combine multiple fields into one (e.g., "First" + "Last" -> "FullName").
Inputs
General
| Data | Description |
|---|---|
| Items | The source array to transform. |
| Script | A JavaScript function definition that defines the mapping logic. |
Outputs
General
| Data | Description |
|---|---|
| Items | The new array containing the transformed items. |
| Count | The number of items in the new array. |
Events
| Signal | Description |
|---|---|
| Changed | Triggered when the mapping operation completes. |
Usage
Writing the Map Script
The script input expects a specific format using a map function builder:
map({
// Direct mapping: OutputProperty: 'InputProperty'
newName: 'name',
// Function mapping: OutputProperty: function(object) { ... }
fullName: function(object) {
return object.get('firstName') + ' ' + object.get('lastName');
},
// Static value
type: function(object) {
return 'User';
}
})
Example Use Cases
- Data Normalization: Convert backend API data (e.g.,
user_id,user_name) to frontend component format (id,title). - Calculated Fields: Add a
totalPricefield to order items by multiplyingquantity*price. - Flattening: Extract a nested property (e.g.,
data.attributes.title) to the top level (title).
Detailed Behavior
- Reactivity: The node listens for changes in the source collection. If an item in the source array updates, the map operation re-runs automatically.
- New Collection: The output is a new collection containing new objects. Modifying the output objects does not affect the source objects.
Troubleshooting
- Script Errors: Check the console for "Error while parsing map script". Ensure you are using the
map({...})syntax correctly. - Undefined Values: If a property doesn't exist on the source object, the mapped value will be
undefined.