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
): booleanCurried signature
typescript
function maxElements<
GenericInput extends readonly unknown[]
>(
maxLength: number
): (input: GenericInput) => booleanParameters
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 elementsset- Modifies an element at a specific index
