Sum
This node calculates the sum of all elements in an array.
The Sum node aggregates values from an array, supporting numbers, strings (concatenation), and objects.
The Sum node takes an array as input and calculates the total sum of its elements. It is versatile: it can sum a simple list of numbers, concatenate a list of strings, or sum a specific property from a list of objects.
| Data | Description |
|---|
| Array | The array to process. Can contain numbers, strings, or objects. |
Object Options
| Data | Description |
|---|
| Key Path | Required if the array contains objects. Specifies the property path to sum (e.g., "price" or "user.stats.score"). |
Actions
| Signal | Description |
|---|
| Do | Triggers the calculation. The result is updated only when this signal is received. |
Outputs
Data
| Data | Description |
|---|
| Sum | The calculated result. Can be a number (sum) or a string (concatenation). |
Signals
| Signal | Description |
|---|
| Done | Triggered when the calculation is successfully completed. |
Usage
Use this node for aggregation tasks, such as calculating totals from a list.
Example Use Cases
- Shopping Cart Total: Sum the "price" property of items in a cart array.
Array: Cart Items (List of objects).
Key Path: "price".
Result: Total cost.
- Score Aggregation: Sum a list of round scores.
Array: [10, 20, 15].
Result: 45.
- String Builder: Join a list of words.
Array: ["Hello", " ", "World"].
Result: "Hello World".
Detailed Behavior
- Type Detection: The node automatically detects if the array contains numbers, strings, or objects based on the first element.
- Object Handling: If the array contains objects,
Key Path is used to extract the value. Nested paths are supported (e.g., "data.value").
- Mixed Types: If any element in the resolved list is a string, the entire operation becomes a string concatenation.
- Null/Undefined: Null or undefined values in the array are ignored.
Troubleshooting
- Result is 0: Check if your array is empty or if the
Key Path is incorrect for object arrays.
- Unexpected Concatenation: If you expected a number but got a string (e.g., "1020" instead of 30), one of your values might be a string. Ensure all inputs are numbers.