Skip to content

maxElements

The maxElements() function checks that an array contains at most a certain number of elements. It is handy for rejecting a list that is too long before an expensive process.

Interactive example

Syntax

Classic signature

typescript
function maxElements<
	GenericInput extends readonly unknown[]
>(
	input: GenericInput,
	maxLength: number
): boolean

Curried signature

typescript
function maxElements<
	GenericInput extends readonly unknown[]
>(
	maxLength: number
): (input: GenericInput) => boolean

Parameters

  • input: Array whose size you want to limit.
  • maxLength: Maximum allowed number.

Return value

true if the number of elements is less than or equal to maxLength, otherwise false.

See also

  • minElements - Checks a minimum number of elements
  • set - Modifies an element at a specific index

Sources

Released under the MIT license.