1.38.0isArray
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
valueunknownrequiredThe 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
Basic usage
Check whether a value is an array.
isArray([1, 2, 3]);
// true
isArray("hello");
// falseType narrowing
The function can narrow an unknown value to unknown[] inside a conditional block.
const value: unknown = [1, 2, 3];
if (isArray(value)) {
value.length;
// value is narrowed to unknown[]
}Empty arrays
Empty arrays are still recognized as arrays.
isArray([]);
// trueOther values
Objects, null, primitives, and other non-array values return false.
isArray({});
// false
isArray(null);
// false
isArray(42);
// false
isArray("hello");
// false