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 notation. These interchangeable forms allow flexibility in how you structure expressions.
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
| array | array | 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
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
}
Theme
Light