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

# Array Tools

> Filter, sort, group, chunk, and transform arrays.

The Array Tools connector provides operations for working with arrays: filtering, sorting, grouping, deduplication, set operations, and more.

<Note>No connection required; this utility connector works out of the box.</Note>

## Tools

<AccordionGroup>
  <Accordion title="filter: Filter by condition">
    <ParamField body="array" type="any[]" required>
      Array to filter.
    </ParamField>

    <ParamField body="key" type="string">
      Object property to filter on (for arrays of objects).
    </ParamField>

    <ParamField body="operator" type="string" required>
      Operator: `equals`, `not_equals`, `contains`, `gt`, `gte`, `lt`, `lte`, `exists`, or `not_exists`.
    </ParamField>

    <ParamField body="value" type="any">
      Value to compare.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": [
        { "name": "Alice", "age": 30 },
        { "name": "Bob", "age": 25 },
        { "name": "Carol", "age": 35 }
      ],
      "key": "age",
      "operator": "gte",
      "value": 30
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": [
        { "name": "Alice", "age": 30 },
        { "name": "Carol", "age": 35 }
      ],
      "count": 2
    }
    ```
  </Accordion>

  <Accordion title="sort: Sort array">
    <ParamField body="array" type="any[]" required>
      Array to sort.
    </ParamField>

    <ParamField body="key" type="string">
      Property to sort by (for arrays of objects).
    </ParamField>

    <ParamField body="order" type="string" default="asc">
      Sort order: `asc` or `desc`.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": [
        { "name": "Carol", "score": 88 },
        { "name": "Alice", "score": 95 },
        { "name": "Bob", "score": 72 }
      ],
      "key": "score",
      "order": "desc"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": [
        { "name": "Alice", "score": 95 },
        { "name": "Carol", "score": 88 },
        { "name": "Bob", "score": 72 }
      ],
      "count": 3
    }
    ```
  </Accordion>

  <Accordion title="unique: Remove duplicates">
    <ParamField body="array" type="any[]" required>
      Array to deduplicate.
    </ParamField>

    <ParamField body="key" type="string">
      Property to check for uniqueness (for arrays of objects).
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": [
        { "city": "Portland", "state": "OR" },
        { "city": "Seattle", "state": "WA" },
        { "city": "Portland", "state": "ME" }
      ],
      "key": "city"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": [
        { "city": "Portland", "state": "OR" },
        { "city": "Seattle", "state": "WA" }
      ],
      "count": 2
    }
    ```
  </Accordion>

  <Accordion title="find: Find first match">
    <ParamField body="array" type="any[]" required>
      Array to search.
    </ParamField>

    <ParamField body="key" type="string" required>
      Property to match on.
    </ParamField>

    <ParamField body="value" type="any" required>
      Value to find.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": [
        { "id": 1, "name": "Alice" },
        { "id": 2, "name": "Bob" },
        { "id": 3, "name": "Carol" }
      ],
      "key": "id",
      "value": 2
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "item": { "id": 2, "name": "Bob" }
    }
    ```
  </Accordion>

  <Accordion title="flatten: Flatten nested arrays">
    <ParamField body="array" type="any[]" required>
      Array to flatten.
    </ParamField>

    <ParamField body="depth" type="number">
      Depth to flatten (all levels if omitted).
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": [1, [2, 3], [4, [5, 6]]],
      "depth": 1
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": [1, 2, 3, 4, [5, 6]],
      "count": 5
    }
    ```
  </Accordion>

  <Accordion title="chunk: Split into chunks">
    <ParamField body="array" type="any[]" required>
      Array to chunk.
    </ParamField>

    <ParamField body="size" type="number" required>
      Chunk size (minimum 1).
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": ["a", "b", "c", "d", "e"],
      "size": 2
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": [["a", "b"], ["c", "d"], ["e"]],
      "count": 3
    }
    ```
  </Accordion>

  <Accordion title="first: Get first N elements">
    <ParamField body="array" type="any[]" required>
      Source array.
    </ParamField>

    <ParamField body="count" type="number" default="1">
      Number of elements to return.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": [10, 20, 30, 40, 50],
      "count": 3
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": [10, 20, 30],
      "count": 3
    }
    ```
  </Accordion>

  <Accordion title="last: Get last N elements">
    <ParamField body="array" type="any[]" required>
      Source array.
    </ParamField>

    <ParamField body="count" type="number" default="1">
      Number of elements to return.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": [10, 20, 30, 40, 50],
      "count": 2
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": [40, 50],
      "count": 2
    }
    ```
  </Accordion>

  <Accordion title="group-by: Group by property">
    <ParamField body="array" type="any[]" required>
      Array to group.
    </ParamField>

    <ParamField body="key" type="string" required>
      Property to group by.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": [
        { "name": "Alice", "department": "Engineering" },
        { "name": "Bob", "department": "Sales" },
        { "name": "Carol", "department": "Engineering" },
        { "name": "Dave", "department": "Sales" }
      ],
      "key": "department"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "entries": {
        "Engineering": [
          { "name": "Alice", "department": "Engineering" },
          { "name": "Carol", "department": "Engineering" }
        ],
        "Sales": [
          { "name": "Bob", "department": "Sales" },
          { "name": "Dave", "department": "Sales" }
        ]
      },
      "count": 2
    }
    ```
  </Accordion>

  <Accordion title="pluck: Extract property values">
    Extract a single property from each object in the array.

    <ParamField body="array" type="any[]" required>
      Array of objects.
    </ParamField>

    <ParamField body="key" type="string" required>
      Property to extract.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": [
        { "id": 1, "name": "Alice" },
        { "id": 2, "name": "Bob" },
        { "id": 3, "name": "Carol" }
      ],
      "key": "name"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": ["Alice", "Bob", "Carol"],
      "count": 3
    }
    ```
  </Accordion>

  <Accordion title="reverse: Reverse order">
    <ParamField body="array" type="any[]" required>
      Array to reverse.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": [1, 2, 3, 4, 5]
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": [5, 4, 3, 2, 1],
      "count": 5
    }
    ```
  </Accordion>

  <Accordion title="shuffle: Randomly shuffle">
    <ParamField body="array" type="any[]" required>
      Array to shuffle.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": [1, 2, 3, 4, 5]
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": [3, 5, 1, 4, 2],
      "count": 5
    }
    ```
  </Accordion>

  <Accordion title="compact: Remove falsy values">
    Removes `null`, `undefined`, `false`, `0`, `""`, and `NaN`.

    <ParamField body="array" type="any[]" required>
      Array to compact.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": [0, 1, false, 2, "", 3, null, 4]
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": [1, 2, 3, 4],
      "count": 4
    }
    ```
  </Accordion>

  <Accordion title="intersection: Common elements">
    Get elements that exist in all provided arrays.

    <ParamField body="arrays" type="any[][]" required>
      Arrays to intersect.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "arrays": [
        [1, 2, 3, 4],
        [2, 4, 6, 8],
        [2, 3, 4, 5]
      ]
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": [2, 4],
      "count": 2
    }
    ```
  </Accordion>

  <Accordion title="difference: Unique elements">
    Get elements in the first array that don't exist in the second.

    <ParamField body="array" type="any[]" required>
      Primary array.
    </ParamField>

    <ParamField body="exclude" type="any[]" required>
      Values to exclude.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": [1, 2, 3, 4, 5],
      "exclude": [2, 4, 6]
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": [1, 3, 5],
      "count": 3
    }
    ```
  </Accordion>

  <Accordion title="union: Merge unique values">
    Get unique values across all arrays.

    <ParamField body="arrays" type="any[][]" required>
      Arrays to union.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "arrays": [
        [1, 2, 3],
        [2, 3, 4],
        [3, 4, 5]
      ]
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": [1, 2, 3, 4, 5],
      "count": 5
    }
    ```
  </Accordion>

  <Accordion title="length: Get array length">
    <ParamField body="array" type="any[]" required>
      Array to measure.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": ["apple", "banana", "cherry"]
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "result": 3
    }
    ```
  </Accordion>

  <Accordion title="slice: Extract portion">
    <ParamField body="array" type="any[]" required>
      Source array.
    </ParamField>

    <ParamField body="start" type="number" default="0">
      Start index.
    </ParamField>

    <ParamField body="end" type="number">
      End index (exclusive).
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": ["a", "b", "c", "d", "e"],
      "start": 1,
      "end": 4
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "items": ["b", "c", "d"],
      "count": 3
    }
    ```
  </Accordion>

  <Accordion title="join: Join to string">
    <ParamField body="array" type="any[]" required>
      Array to join.
    </ParamField>

    <ParamField body="separator" type="string" default=",">
      Separator between elements.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "array": ["alice", "bob", "carol"],
      "separator": " | "
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "result": "alice | bob | carol"
    }
    ```
  </Accordion>
</AccordionGroup>
