Skip to content

inArray

The inArray function checks whether a given element exists within an array. It returns true if the array contains a matching element, and false if it does not. This function is the inverse of arrayContains.

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
elementTtrueT must be either string, bool, number, interval, timestamp, regexp or enum
arrayarray of type TtrueMust be an array where each element is of the same type T as defined in the element field (i.e., one of: string, bool, number, interval, timestamp, regexp, or enum).

Example - Check if a particular IP appears in a block list

Consider the following log, from a router:

{
  "client_ip": "192.168.1.105",
}

We can check if client_ip exists in an array of ip addresses.

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'])

Result

The query will return true since the IP address 192.168.1.105 is in the provided array.