Skip to main content

isTypedArray()

isTypedArray(value): value is TypedArray

Checks if value is a TypedArray.

DEPRECATED

Use ArrayBuffer.isView() directly instead. Note: ArrayBuffer.isView() also returns true for DataView.


Parametersโ€‹

value: unknownโ€‹

The value to check.


Returns: value is TypedArrayโ€‹

true if value is a TypedArray, else false.


See Alsoโ€‹


Sinceโ€‹

2.0.0


Also known asโ€‹

isTypedArray (Lodash, es-toolkit) ยท โŒ (Remeda, Radashi, Ramda, Effect, Modern Dash, Antfu)


Exampleโ€‹

// โŒ Deprecated approach
isTypedArray(new Uint8Array(2)); // => true
isTypedArray(new Float32Array()); // => true
isTypedArray([1, 2, 3]); // => false

// โœ… Recommended approach
ArrayBuffer.isView(new Uint8Array(2)); // => true
ArrayBuffer.isView(new Float32Array()); // => true
ArrayBuffer.isView([1, 2, 3]); // => false

// Note: ArrayBuffer.isView also matches DataView
ArrayBuffer.isView(new DataView(new ArrayBuffer(2))); // => true

How it works?โ€‹

Checks if value is a typed array. Deprecated: Use ArrayBuffer.isView() or instanceof checks.

Native Equivalentโ€‹

// โŒ isTypedArray(value)
// โœ… ArrayBuffer.isView(value) && !(value instanceof DataView)

Use Casesโ€‹

Check typed array ๐Ÿ“Œโ€‹

Check if value is a TypedArray.

ArrayBuffer.isView(new Uint8Array(2));   // true
ArrayBuffer.isView(new Float32Array()); // true
ArrayBuffer.isView([1, 2, 3]); // false

Handle binary dataโ€‹

Detect binary data for special handling.

function processData(data: unknown) {
if (ArrayBuffer.isView(data)) {
return processBinary(data);
}
return processJSON(data);
}