Skip to content

Keyword array reduce

Oliver Atkinson edited this page May 10, 2026 · 1 revision

array_reduce

Reduces an array to a single value.

Each iteration receives an item context with:

  • item: the current array element
  • index: the current zero-based index
  • accumulator: the current accumulated value

Shape

{
  "{returns}": {
    "array_reduce": {
      "array": [],
      "initial": 0,
      "next": 0
    }
  }
}

Example

This example uses the optional eval keyword as the reducer.

{
  "{returns}": {
    "array_reduce": {
      "array": [2, 3, 5],
      "initial": 0,
      "next": {
        "{returns}": {
          "eval": {
            "expression": "accumulator + item",
            "context": {
              "accumulator": { "{returns}": { "item": ["accumulator"] } },
              "item": { "{returns}": { "item": ["item"] } }
            }
          }
        }
      }
    }
  }
}

The result is 10.

Clone this wiki locally