# `isEmpty`

## Description

Returns `true` if the array contains no elements, or `false` otherwise.

- Supported element types include `string`, `bool`, `number`, `interval`, `timestamp`, `regexp`, and `enum`.

## Syntax

Like many functions in DataPrime, `isEmpty` supports [two notations](https://coralogix.com/docs/dataprime/language-reference/functions-reference/index.md), **function** and **method** notation. These interchangeable forms allow flexibility in how you structure expressions.

```dataprime
isEmpty(array: array<T>): bool
```

```dataprime
(array: array<T>).isEmpty(): bool
```

## Arguments

| Name  | Type  | Required | Description                      |
| ----- | ----- | -------- | -------------------------------- |
| array | array | **true** | The array to check for emptiness |

## Example

**Use case: Check if an array is empty**

You can directly test whether an array has any elements:

```dataprime
create is_empty from isEmpty(my_array)
```

This produces a new boolean field indicating whether the array is empty.

**Use case 2: Optimize execution by skipping work when arrays are empty**

Suppose you have documents like the following:

```json
{
    "names": ["Chip", "Ruby", "Glitch"]
},
{
    "names": []
}
```

If you want to join names into a string but avoid unnecessary computation for empty arrays, you can combine `isEmpty` with an `if` statement:

### Example query

```dataprime
create msg from if(!names.isEmpty(), names.arrayJoin(','), '')
```

```dataprime
create msg from if(!isEmpty(names), names.arrayJoin(','), '')
```

### Example output

For the above input, the results will look like:

```json
{
    "names": ["Chip", "Ruby", "Glitch"],
    "msg": "Chip,Ruby,Glitch"
},
{
    "names": [],
    "msg": ""
}
```
