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, andenum.
Syntax
Like many functions in DataPrime, arrayReplaceAt supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
| array | array | 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:
By replacing the element at position 0 with "NewVal1", you ensure consistent schema values across documents.
Example query
Example output
The result will replace the outdated value at the given index:
Theme
Light