Skip to main content

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

DataDescription
ItemsThe source array to transform.
ScriptA JavaScript function definition that defines the mapping logic.

Outputs

General

DataDescription
ItemsThe new array containing the transformed items.
CountThe number of items in the new array.

Events

SignalDescription
ChangedTriggered 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

  1. Data Normalization: Convert backend API data (e.g., user_id, user_name) to frontend component format (id, title).
  2. Calculated Fields: Add a totalPrice field to order items by multiplying quantity * price.
  3. Flattening: Extract a nested property (e.g., data.attributes.title) to the top level (title).

Detailed Behavior

  1. Reactivity: The node listens for changes in the source collection. If an item in the source array updates, the map operation re-runs automatically.
  2. 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.