n8n LabAdvanced
Sum Values with reduce() in n8n
Calculate an order total from its line items without adding a Code node.
Live Execution Simulator
Idle
π₯
Incoming Data
βοΈ
n8n Node
π―
Next Step
> Ready. Type your expression below and click "Check Answer" to run the node.
Incoming Payload / Data:
{
"items": [
{ "name": "Plan", "price": 10 },
{ "name": "Add-on", "price": 25 }
]
}
$json.items.reduce((sum, item) =>
, 0)
βοΈ Your expression is executed against test data β any correct solution passes. +30 XP
β Solution & explanation
$json.items.reduce((sum, item) => sum + item.price, 0)
Output: 35
reduce() walks through the array carrying an accumulator (sum). It starts at 0 (the second argument) and each step returns sum + item.price.π‘ Pro tip: Simpler with n8n helpers: $json.items.pluck('price').sum().
Also accepted: item.price + sum