> ## Documentation Index
> Fetch the complete documentation index at: https://docs.metrics-man.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Reduce

# \$reduce

The `$reduce` operator applies a function to each element in an array to reduce it to a single value.

## Input

* An array containing an array to reduce, an initial value, and a reducer function

## Output

* A single value resulting from the reduction

## Examples

### Sum Array Values

```json theme={null}
{
  "$reduce": [
    [1, 2, 3, 4, 5],
    0,
    {
      "$add": [
        {
          "$var": ["accumulator"]
        },
        {
          "$var": ["currentValue"]
        }
      ]
    }
  ]
}
```

Result: `15`

### Concatenate Strings

```json theme={null}
{
  "$reduce": [
    ["a", "b", "c"],
    "",
    {
      "$concat": [
        {
          "$var": ["accumulator"]
        },
        {
          "$var": ["currentValue"]
        }
      ]
    }
  ]
}
```

Result: `"abc"`
