CyrefJS
CCyrefJS
فا
Back to documentation
Type/Since 1.38.0

isArray

Checks whether a value is an array and provides a TypeScript type guard for array narrowing.

isArray(value):value is unknown[]

Implementation

The function delegates the runtime check directly to JavaScript's built-in Array.isArray().

Type guard

The return type is `value is unknown[]`, making the function a TypeScript type guard. After a successful check, TypeScript can treat the value as an array of unknown elements within the narrowed scope.

Runtime behavior

The check recognizes actual JavaScript arrays, including empty arrays. It returns false for objects that merely resemble arrays.

Parameters

valueunknownrequired

The value to check.

Returns

value is unknown[]

Returns true when the value is an array; otherwise returns false. When true, TypeScript narrows the value to unknown[].

Examples

01

Basic usage

Check whether a value is an array.

TypeScript
isArray([1, 2, 3]);
// true

isArray("hello");
// false
02

Type narrowing

The function can narrow an unknown value to unknown[] inside a conditional block.

TypeScript
const value: unknown = [1, 2, 3];

if (isArray(value)) {
  value.length;
  // value is narrowed to unknown[]
}
03

Empty arrays

Empty arrays are still recognized as arrays.

TypeScript
isArray([]);
// true
04

Other values

Objects, null, primitives, and other non-array values return false.

TypeScript
isArray({});
// false

isArray(null);
// false

isArray(42);
// false

isArray("hello");
// false
Built with@cyref/js·Official documentation