---
updatedAt: 2025-05-20T20:28:12.000Z
agentTools:
  projectIndex: https://docs.documotor.com/llms.txt
---

# sum

Sum the numbers in an array

# Definition

`number sum(array[number] $array)`

Sums all the elements of a number array. An error is raised if there is an element that is neither a <Glossary>number</Glossary> nor a <Glossary>boolean</Glossary>.

# Parameters

<Glossary>array</Glossary>\[<Glossary>number</Glossary>] `$array`

An array to sum the elements of.

# Returns

<Glossary>number</Glossary>

The sum of all the elements of `$array`.

# Examples

```text Transformation
{
  a: sum(`[1, 2, 3]`),
  b: sum(`[-1, -2, 3]`),
  c: sum(`[1.0, -2.5, 3.1]`),
  d: sum(`[true, false, 0]`),
  e: sum(`[]`),
  f: sum(['string', `1`, `0`])       // Error
}
```

```json Result
{
  "a": 6,
  "b": 0,
  "c": 1.6,
  "d": 1,
  "e": 0
}
```