arrayContains - Test if array contains an element
The arrayContains
function returns true
if an array includes a matching element, or false
if that element is not included. arrayContains
is the mirror version of inArray.
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 of type T | true | T must be either string , bool , number , interval , timestamp , regexp or enum |
element | T | true | T must be either 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 firewall:
{
"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"
]
}
We can see that the firewall blocked a given IP address. If we want to check our client_ip
against the block list, we can do this using arrayContains
:
This will create a field, is_blocked_ip
that is true
if the client_ip
field appears in the blocked_ips
list, otherwise false
.
Theme
Light