Skip to content

inArray

Description

Returns true if the specified element exists within the array, or false if it does not.

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

Syntax

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

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

Arguments

NameTypeRequiredDescription
elementTtrueThe element to check for in the array
arrayarraytrueThe array to search, must contain elements of the same type as element

Example

Use case: Check if a client IP appears in a block list

Suppose you have a log entry with a client IP. Consider the following input:

{
    "client_ip": "192.168.1.105"
}

By checking whether the client_ip value exists in an array of blocked IP addresses, you can identify whether the request should be blocked.

filter inArray(client_ip, ['192.168.1.105', '192.168.1.112', '192.168.1.32'])
filter client_ip.inArray(['192.168.1.105', '192.168.1.112', '192.168.1.32'])

Output

The result will return true since "192.168.1.105" is included in the array:

{
    "client_ip": "192.168.1.105",
    "is_blocked": true
}