predictype

predictype v0.8.1


predictype / predicates/arrays/arrayIndexMembership / arrayIndexMembership

Function: arrayIndexMembership()

arrayIndexMembership<T>(source, oper, index, target): boolean

Defined in: predicates/arrays/arrayIndexMembership.ts:31

Checks if the value at a specific index in an array is (or is not) included in a target array, using the specified operation.

Type Parameters

T

T

Type of the array elements.

Parameters

source

T[]

The source array.

oper

ArrayIndexMembershipOper

The membership operation to perform (e.g. ‘at_index_in’).

index

number

The index in the array to check.

target

T[]

The array of values to check for inclusion/exclusion.

Returns

boolean

True if the membership check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example

const arr = [10, 20, 30];
const idx1 = 1;
const idx2 = 2;
const values = [10, 20];

arrayIndexMembership(arr, 'at_index_in', idx1, values); // true
arrayIndexMembership(arr, 'at_index_not_in', idx2, values); // true

Remarks

Supported Operators: