Sum
This node calculates the sum of all elements in an array, with support for objects and string concatenation.
The Sum node can sum numeric arrays, concatenate string arrays, or extract and sum values from object arrays.
The Sum node is a versatile calculation node that processes arrays of different data types. For numeric arrays, it calculates the mathematical sum. For string arrays, it concatenates all elements. For object arrays, it can extract values using a key path and sum or concatenate them.
Inputs
Input
| Data | Description |
|---|---|
| Array | The array to process (numbers, strings, or objects) |
Object Options
| Data | Description |
|---|---|
| Key Path | Path to extract values from objects (required for object arrays) |
Actions
| Signal | Description |
|---|---|
| Do | Triggers the sum calculation |
Outputs
| Data | Description |
|---|---|
| Sum | The calculated sum or concatenated result |
| Signal | Description |
|---|---|
| Done | Triggered when the calculation is complete |
Usage
The Sum node automatically detects the array type and performs the appropriate operation:
Numeric Arrays
- Calculates the mathematical sum of all numbers
- Filters out null/undefined values
- Returns 0 for empty arrays
String Arrays
- Concatenates all strings together
- Converts other types to strings before concatenation
- Returns empty string for empty arrays
Object Arrays
- Requires a Key Path to specify which property to extract
- Supports nested object access using comma-separated paths
- Can sum numeric properties or concatenate string properties
Example Use Cases
- Financial Calculations: Sum order totals, tax amounts, or fees
- Data Analytics: Calculate totals from data sets
- String Building: Concatenate text elements or create comma-separated lists
- Game Development: Sum scores, damage values, or resource counts
- Form Processing: Calculate totals from user inputs
Key Path Examples
For object arrays, use the Key Path to specify which property to extract:
// For objects like: [{price: 10}, {price: 20}, {price: 30}]
Key Path: "price" // Result: 60
// For nested objects: [{item: {cost: 5}}, {item: {cost: 3}}]
Key Path: "item,cost" // Result: 8
// For string concatenation: [{name: "A"}, {name: "B"}]
Key Path: "name" // Result: "AB"
Error Handling
The node will handle errors gracefully:
- Empty arrays return appropriate default values (0 or empty string)
- Invalid key paths throw descriptive error messages
- Non-array inputs are rejected with clear error messages
- Arrays exceeding 1,000,000 elements are rejected for performance
Data Type Detection
The node automatically detects array content:
- Numbers: Performs mathematical addition
- Strings: Performs concatenation
- Objects: Requires key path for value extraction
- Mixed: Any string presence triggers concatenation mode