Skip to content

arrayRemove - Remove given element from array

arrayRemove will remove a given element from an array and return the modified array.

Syntax

Like many functions in DataPrime, arrayRemove supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

arrayRemove(array: array<T>, element: T): array<T>
array: array<T>.arrayRemove(element: T): array<T>

Arguments

NameTypeRequiredDescription
arrayarray of type TtrueT must be either string, bool, number, interval, timestamp, regexp or enum
elementTtrueT must be either string, bool, number, interval, timestamp, regexp or enum

Example - Removing a job from the middle of a queue

Consider the following document:

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

Removing an item from the array can be done as follows:

replace values with arrayRemove(values, 'Job 3')
replace values with values.arrayRemove('Job 3')

This results in the following document:

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

Try it yourself

Open up your explore screen and enter the following command:

create values from ['Job 1', 'Job 2', 'Job 3', 'Job 4']
| create updated_values from values.arrayRemove('Job 3')