Skip to main content

isIn()

isIn<T>(array): (value) => boolean

Creates a predicate function that determines if a value exists in a given array.

Type Parameters

T

T

The type of the array elements and value

Parameters

array

T[]

The array to search within

Returns

(value): boolean

Parameters

value

T

Returns

boolean

Remarks

  • Pure function with no side effects
  • Uses Array.prototype.includes() for membership testing
  • Uses strict equality (===) for element comparison
  • Works with any type that can be compared with strict equality
  • Useful for array filtering and validation predicates

Example

const isValidStatus = isIn(['pending', 'approved', 'rejected']);
isValidStatus('pending'); // true
isValidStatus('unknown'); // false

const isPrime = isIn([2, 3, 5, 7, 11, 13]);
isPrime(7); // true
isPrime(10); // false

// Useful with arrays
const userIds = [101, 102, 103, 104];
const activeUsers = [101, 103, 105, 106];
const validActiveUsers = activeUsers.filter(isIn(userIds)); // [101, 103]