Skip to main content

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.

Inputs

Input

DataDescription
ArrayThe array to process. Can contain numbers, strings, or objects.

Object Options

DataDescription
Key PathRequired if the array contains objects. Specifies the property path to sum (e.g., "price" or "user.stats.score").

Actions

SignalDescription
DoTriggers the calculation. The result is updated only when this signal is received.

Outputs

Data

DataDescription
SumThe calculated result. Can be a number (sum) or a string (concatenation).

Signals

SignalDescription
DoneTriggered when the calculation is successfully completed.

Usage

Use this node for aggregation tasks, such as calculating totals from a list.

Example Use Cases

  1. 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.
  2. Score Aggregation: Sum a list of round scores.
    • Array: [10, 20, 15].
    • Result: 45.
  3. String Builder: Join a list of words.
    • Array: ["Hello", " ", "World"].
    • Result: "Hello World".

Detailed Behavior

  1. Type Detection: The node automatically detects if the array contains numbers, strings, or objects based on the first element.
  2. Object Handling: If the array contains objects, Key Path is used to extract the value. Nested paths are supported (e.g., "data.value").
  3. Mixed Types: If any element in the resolved list is a string, the entire operation becomes a string concatenation.
  4. 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.