Overview
Array operators enable checking if a value exists in a collection. Rule Engine JS provides two array membership operators:in
Check if value exists in array
notIn
Check if value does NOT exist in array
Architecture
Array operators are implemented in theArrayOperators class extending BaseOperator:
Source Files:
- Array operators:
src/operators/array.js - Base operator:
src/operators/base/BaseOperator.js - Type utilities:
src/utils/TypeUtils.js - Unit tests:
tests/unit/operators/array.test.js
Key Features
- Dynamic arrays - Array can be a field path or literal value
- Dynamic values - Value to check can also be a field path
- Strict/loose comparison - Control type coercion behavior
- Case sensitive - Exact matching for strings by default
- Comprehensive validation - Validates right operand is an array
in - Array Membership
Check if a value exists in an array.
Syntax
Parameters
The value to search for - field path or literal value
The array to search in - field path or literal array
Configuration options
Returns
boolean - true if value exists in array, false otherwise
Examples
- Basic Membership
- Dynamic Arrays
- Number Arrays
- Case Sensitivity
- With Rule Helpers
Common Use Cases
Role-Based Access Control
Role-Based Access Control
Permission Checks
Permission Checks
Feature Flags
Feature Flags
Tag Filtering
Tag Filtering
Status Validation
Status Validation
Performance: Array membership uses optimized
Array.some() with early exit for better performance.notIn - Array Exclusion
Check if a value does NOT exist in an array (inverse of in).
Syntax
Parameters
The value to check for exclusion - field path or literal value
The array to check against - field path or literal array
Configuration options
Returns
boolean - true if value does NOT exist in array, false if it exists
Examples
- Basic Exclusion
- Account Validation
- Security Checks
- Content Filtering
- Dynamic Exclusion
Common Use Cases
Blacklist Validation
Blacklist Validation
Status Guards
Status Guards
Platform Restrictions
Platform Restrictions
File Type Restrictions
File Type Restrictions
Error Handling
Common Errors
Non-Array Right Operand
Non-Array Right Operand
Undefined Array Field
Undefined Array Field
Missing Arguments
Missing Arguments
Literal String Instead of Array
Literal String Instead of Array
Safe Error Handling
Type Coercion & Comparison
Array operators useTypeUtils.isEqual() for element comparison:
Loose Mode (Default)
Strict Mode
Comparison Table
| Value Type | Array Element | Loose Mode | Strict Mode |
|---|---|---|---|
1 | 1 | ✅ Match | ✅ Match |
1 | '1' | ✅ Match | ❌ No match |
'true' | true | ❌ No match | ❌ No match |
null | undefined | ❌ No match | ❌ No match |
Related Operators
Comparison Operators
eq, neq for single value checks
String Operators
contains, startsWith, endsWith
Special Operators
isNull, isNotNull, between
Logical Operators
and, or, not for combining rules
State Operators
changed, changedTo, changedFrom
All Operators
Complete operator reference
