For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/predicate/isLength.md.

isLength es-toolkit

Checks if a value is a valid array length.

const result = isLength(value);

Usage

isLength(value)

Use isLength when you want to check if a value is a valid array length. A valid length must be an integer between 0 and Number.MAX_SAFE_INTEGER.

import { isLength } from 'es-toolkit/predicate';

// Valid lengths
console.log(isLength(0)); // true
console.log(isLength(42)); // true
console.log(isLength(Number.MAX_SAFE_INTEGER)); // true

// Invalid lengths
console.log(isLength(-1)); // false (negative)
console.log(isLength(1.5)); // false (decimal)
console.log(isLength(Number.MAX_SAFE_INTEGER + 1)); // false (unsafe integer)
console.log(isLength('42')); // false (string)
console.log(isLength(null)); // false (null)

Can also be used as a type guard in TypeScript.

function processLength(value: unknown) {
  if (isLength(value)) {
    // Now value is narrowed to number type
    console.log(value.toFixed(2));
  }
}

Parameters

valueunknownrequired

The value to check if it's a valid length.

Returns

Returns true if the value is a valid length, false otherwise.

boolean
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.