Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Farray%2Farrayreplaceat.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%2Farrayreplaceat.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `arrayReplaceAt`

## Description

Returns a new array with the element at the specified position replaced by a new value.

* 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, `arrayReplaceAt` 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

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

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

## Arguments

| Name       | Type       | Required | Description                                      |
| ---------- | ---------- | -------- | ------------------------------------------------ |
| `array`    | `array<T>` | **true** | The array to modify                              |
| `position` | `number`   | **true** | The index of the element to replace (0-indexed)  |
| `value`    | `T`        | **true** | The replacement value, must match the array type |

## Example

**Use case: Replace outdated schema values at a specific position**

Suppose you have a list of values where the first entry uses an outdated schema. Consider the following inputs:

```
{

    "values": ["NewVal1", "NewVal2", "NewVal3"]

},

{

    "values": ["OldVal1", "NewVal2", "NewVal3"]

}
```

By replacing the element at position `0` with `"NewVal1"`, you ensure consistent schema values across documents.

### Example query

* Function notation
* Method notation

```
create updated_values from arrayReplaceAt(values, 0, 'NewVal1')
```

```
create updated_values from values.arrayReplaceAt(0, 'NewVal1')
```

### Example output

The result will replace the outdated value at the given index:

```
{

    "values": ["NewVal1", "NewVal2", "NewVal3"]

},

{

    "values": ["NewVal1", "NewVal2", "NewVal3"]

}
```
