Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Farray%2Farrayinsertat.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Farray%2Farrayinsertat.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `arrayInsertAt`

## Description

Returns a new array with an element inserted at the specified position.

* The element type must match the array type.
* Supported element types include `string`, `bool`, `number`, `interval`, `timestamp`, `regexp`, and `enum`.

## Syntax

Like many functions in DataPrime, `arrayInsertAt` supports<!-- --> [two notations](https://docs-docusaurus.kinsta.page/dataprime/language-reference/functions-reference/.md),<!-- --> **function** and **method**. These interchangeable forms allow flexibility in how you structure expressions.

* Function notation
* Method notation

```
arrayInsertAt(array: array<T>, position: number, value: T): array<T>
```

```
(array: array<T>).arrayInsertAt(position: number, value: T): array<T>
```

## Arguments

| Name       | Type       | Required | Description                                      |
| ---------- | ---------- | -------- | ------------------------------------------------ |
| `array`    | `array<T>` | **true** | The array to modify                              |
| `position` | `number`   | **true** | The index at which to insert the new element     |
| `value`    | `T`        | **true** | The element to insert, must match the array type |

## Example

**Use case: Insert an item into the middle of a queue**

Suppose you have a list of jobs but notice one is missing. Consider the following input:

```
{

    "values": ["Job 1", "Job 2", "Job 4"]

}
```

By inserting `'Job 3'` at position `2`, you restore the intended sequence of jobs.

### Example query

* Function notation
* Method notation

```
replace values with arrayInsertAt(values, 2, 'Job 3')
```

```
replace values with values.arrayInsertAt(2, 'Job 3')
```

### Example output

The result will include the new element at the specified index:

```
{

    "values": ["Job 1", "Job 2", "Job 3", "Job 4"]

}
```
