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

> Reference material for ARRAY_COUNT function

# ARRAY_COUNT

Counts the number of elements in an array for which `function(array[i])` evaluates to TRUE, if a function is provided.
If `<function>` is not provided, counts the number of elements in the array that evaluate to TRUE, equivalent to using `x -> x`.
To count the elements in an array without any conditions, use the [ARRAY\_LENGTH](/reference-sql/functions-reference/array/array-length) function instead.

## Syntax

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
ARRAY_COUNT(<function>, <array>)
```

## Parameters

| Parameter    | Description                                                                                                                                                                      | Supported input types                                               |
| :----------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------ |
| `<function>` | Optional. A [Lambda function](/guides/sql-dialect/arrays#lambda-function-general-syntax) used to check elements in the array. If `<function>` is not provided, `x -> x` is used. | Any Lambda function returning `BOOLEAN`                             |
| `<array>`    | An array of elements                                                                                                                                                             | Any `ARRAY` type if `<function>` is provided, else `ARRAY(BOOLEAN)` |

## Return Type

`INTEGER`

## Examples

The example below searches through the array for any elements that are greater than 3. Only one number that matches this criteria is found, so the function returns `1`.

<div className="query-window">
  ```
  SELECT ARRAY_COUNT(x -> x > 3, [1, 2, 3, 9, NULL]) AS levels;
  ```

  | levels <span>int</span> |
  | :---------------------- |
  | 1                       |

  <p><span>Rows: 1</span><span>Execution time: 6.52ms</span></p>
</div>

In this example, there is no `<function>` provided in the `ARRAY_COUNT` function. This means the function will count all of the elements in the array that evaluate to TRUE. Below, this is the case for all values except `FALSE` and `null`:

<div className="query-window">
  ```
  SELECT ARRAY_COUNT([TRUE, FALSE, 2::BOOLEAN, 3 IS NOT NULL, NULL IS NULL, NULL]) AS levels;
  ```

  | levels <span>int</span> |
  | :---------------------- |
  | 4                       |

  <p><span>Rows: 1</span><span>Execution time: 6.16ms</span></p>
</div>
