Skip to content

arrayAppend - Add an element to an array

The arrayAppend function will add an element to a given array.

Syntax

arrayAppend(array: array<T>, 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 - Adding an extra element to a list for easier processing

If we want to do some array processing, but we're missing some values, the arrayAppend function is very useful for adding missing elements where they appear in other fields. For example, consider the following document:

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

We can include my_other_value in my_values like so:

replace my_values with my_values.append(my_other_value)

This will result in the following document:

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