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

# `arrayReplaceAll`

## Description

Returns a new array where all instances of a specified value are replaced with 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, `arrayReplaceAll` 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

```
arrayReplaceAll(array: array<T>, value: T, newValue: T): array<T>
```

```
(array: array<T>).arrayReplaceAll(value: T, newValue: T): array<T>
```

## Arguments

| Name       | Type       | Required | Description                                      |
| ---------- | ---------- | -------- | ------------------------------------------------ |
| `array`    | `array<T>` | **true** | The array to modify                              |
| `value`    | `T`        | **true** | The value to replace                             |
| `newValue` | `T`        | **true** | The replacement value, must match the array type |

## Example

**Use case: Replace outdated schema values in arrays**

Suppose you have a list of values where some still use an outdated schema. Consider the following inputs:

```
{

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

},

{

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

}
```

By replacing all occurrences of `"OldVal1"` with `"NewVal1"`, you ensure data consistency before further processing.

### Example query

* Function notation
* Method notation

```
create updated_values from arrayReplaceAll(values, 'OldVal1', 'NewVal1')
```

```
create updated_values from values.arrayReplaceAll('OldVal1', 'NewVal1')
```

### Example output

The result will replace all outdated values:

```
{

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

},

{

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

}
```
