predictype / predicates/arrays/arrayIndexComparison / arrayIndexComparison
arrayIndexComparison<
T
>(source
,oper
,index
,target
):boolean
Defined in: predicates/arrays/arrayIndexComparison.ts:34
Compares the value at a specific index in an array with a target value, using the specified operation.
T
Type of the array elements.
T
[]
The source array.
The comparison operation to perform (e.g. ‘at_index_equals’).
number
The index in the array to compare.
T
The value to compare against the value at the given index.
boolean
True if the comparison is valid according to the operator, otherwise false.
If the operation is not recognized.
const arr = [10, 20, 30];
const idx1 = 1;
const idx2 = 2;
const val1 = 20;
const val2 = 25;
arrayIndexComparison(arr, 'at_index_equals', idx1, val1); // true
arrayIndexComparison(arr, 'at_index_greater_than', idx2, val2); // true
Supported Operators: