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, andenum.
Syntax
Like many functions in DataPrime, inArray supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
| element | T | true | The element to check for in the array |
| array | array | true | The 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:
By checking whether the client_ip value exists in an array of blocked IP addresses, you can identify whether the request should be blocked.
Example query
Example output
The result will return true since "192.168.1.105" is included in the array:
Theme
Light