# length

[Read this page in HTML](https://www.scopedb.io/docs/reference/functions/semi-structured-data/length)

Counts the elements in an array.

## Syntax

```scopeql
length(<array>)
```

## Arguments

| Argument  | Type    | Description                                             |
| --------- | ------- | ------------------------------------------------------- |
| `<array>` | `array` | Array to measure. Cast an `any` value to `array` first. |

## Returns

Returns `int`. Counts all elements, including NULL. An empty array has length 0. Returns NULL if the input is NULL.

## Examples

Measure basket size from the item-ID array attached to each order.

```scopeql
VALUES
    ('o-17', ['sku-1', 'sku-2', 'sku-3']),
    ('o-42', ['sku-9']), ('o-63', [])
SELECT $0 AS order_id, $1 AS item_ids
SELECT order_id, length(item_ids) AS item_count
```

```text
+----------+------------+
| order_id | item_count |
+----------+------------+
| o-17     | 3          |
| o-42     | 1          |
| o-63     | 0          |
+----------+------------+
```
