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 all functions in DataPrime, inArray supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

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

Arguments

Name Type Required Description
element T true T must be either string, bool, number, interval, timestamp, regexp or enum
array array of type T true Must 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.

Function notation

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

Method notation

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.