Skip to content

arrayContains

Description

Returns true if an array includes the specified element, or false if it does not.

  • This function is the mirror version of inArray.
  • Supported element types include string, bool, number, interval, timestamp, regexp, and enum.

Syntax

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

arrayContains(array: array<T>, element: T): bool
(array: array<T>).arrayContains(element: T): bool

Arguments

NameTypeRequiredDescription
arrayarraytrueThe array to search
elementTtrueThe element to check for in the array

Example

Use case: Check if a client IP is present in a block list.

Suppose you have a firewall log that records blocked IPs. Consider the following input:

{
    "action": "BLOCK",
    "client_ip": "134.56.32.98",
    "blocked_ips": [
        "134.56.32.91",
        "134.56.32.93",
        "134.56.32.90",
        "134.56.32.105"
    ]
}

By checking whether client_ip is contained in blocked_ips, you can determine if the request came from a blocked address.

create is_blocked_ip from arrayContains(blocked_ips, client_ip)
create is_blocked_ip from blocked_ips.arrayContains(client_ip)

Output

The result will include a new field is_blocked_ip with a boolean value:

{
    "action": "BLOCK",
    "client_ip": "134.56.32.98",
    "blocked_ips": [
        "134.56.32.91",
        "134.56.32.93",
        "134.56.32.90",
        "134.56.32.105"
    ],
    "is_blocked_ip": false
}