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, andenum.
Syntax
Like many functions in DataPrime, arrayContains supports two notations, function and method. These interchangeable forms allow flexibility in how you structure expressions.
- Function notation
- Method notation
arrayContains(array: array<T>, element: T): bool
(array: array<T>).arrayContains(element: T): bool
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
array | array<T> | true | The array to search |
element | T | true | The 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.
Example query
- Function notation
- Method notation
create is_blocked_ip from arrayContains(blocked_ips, client_ip)
create is_blocked_ip from blocked_ips.arrayContains(client_ip)
Example 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
}