ArrayBuffer.isView(value) is a static method that answers one question: is this value a view over an ArrayBuffer? A view is any typed array, such as Uint8Array or Float64Array, or a DataView. It returns false for the raw ArrayBuffer itself, for plain arrays, and for every other value.
Remember
ArrayBuffer.isView(value) → true | false
new Uint8Array(4) → true (typed array)
new DataView(buffer) → true (DataView)
buffer → false (raw memory, not a view)
[1, 2, 3] → false (plain array)
call: ArrayBuffer.isView(x) // static, not buffer.isView(x)
Syntax
Call isView on the ArrayBuffer constructor and pass any value.
JavaScript
ArrayBuffer.isView(value)
Call
What it does
ArrayBuffer.isView(value)
Returns true when value is a typed array or a DataView.
ArrayBuffer.isView()
No argument: the value is undefined, so the answer is false.
Built into JavaScript since ES2015; no import is needed in browsers, workers, Node.js, Deno, or Bun.
Library declarations
JavaScript
ArrayBuffer.isView(value) // returns true or false
// true: every typed array (Uint8Array, Int16Array, Float64Array, ...)
// and DataView
// false: ArrayBuffer, SharedArrayBuffer, plain arrays, strings, null, ...
Parameters
Parameter
Description
value
Any value to test. If you leave it out it is undefined, and the answer is false.
Return Value
Return Value
Description
boolean
true if value is a typed array or a DataView; otherwise false.
JavaScript Examples
Example 1 — Which Values Are Views?
Create one buffer, put two different views on it, and test them next to values that are not views.
One buffer, two views.bytes and view both look at the same 8 bytes of buffer; creating them copies nothing.
Views answer true. Typed arrays and DataView are the two kinds of view, so the first two checks print true.
Everything else is false. The raw buffer, a plain number array, and null are not views. isView returns false for them without throwing.
Example 2 — Accept a Buffer or a View
Binary APIs often accept "an ArrayBuffer or a typed array", for example the result of file.arrayBuffer() or a Uint8Array you built yourself. isView lets one helper turn either into a Uint8Array over exactly the right bytes.
JavaScript
function toBytes(input) {
if (ArrayBuffer.isView(input)) {
return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
}
if (input instanceof ArrayBuffer) {
return new Uint8Array(input);
}
throw new TypeError("Expected an ArrayBuffer or a view");
}
const raw = new Uint8Array([10, 20, 30, 40, 50]).buffer;
const middle = new Uint8Array(raw, 1, 3);
const words = new Uint16Array(2);
console.log(JSON.stringify(Array.from(toBytes(raw)))); // [10,20,30,40,50]
console.log(JSON.stringify(Array.from(toBytes(middle)))); // [20,30,40]
console.log(toBytes(words).length); // 4
try {
toBytes("hello");
} catch (err) {
console.log(err.message); // Expected an ArrayBuffer or a view
}
[10,20,30,40,50]
[20,30,40]
4
Expected an ArrayBuffer or a view
How It Works
Views first. isView catches every typed array and DataView. Passing byteOffset and byteLength keeps middle to its 3 bytes instead of the whole 5-byte buffer.
Raw buffers second. An ArrayBuffer fails isView, so the instanceof ArrayBuffer branch wraps all of its bytes.
Element size does not matter. Two 16-bit items in words occupy 4 bytes, so the byte view has length 4. A string reaches the final throw.
Example 3 — Describe Any Binary Value
A logging helper that reports what kind of binary value it got. isView covers every typed array at once, so you need no per-type checks.
JavaScript
function describe(value) {
if (value instanceof DataView) {
return "DataView over " + value.byteLength + " bytes";
}
if (ArrayBuffer.isView(value)) {
return value.constructor.name + " with " + value.length + " items";
}
if (value instanceof ArrayBuffer) {
return "ArrayBuffer of " + value.byteLength + " bytes";
}
return "not binary data";
}
const buffer = new ArrayBuffer(16);
console.log(describe(new Float64Array(buffer))); // Float64Array with 2 items
console.log(describe(new DataView(buffer, 4, 8))); // DataView over 8 bytes
console.log(describe(buffer)); // ArrayBuffer of 16 bytes
console.log(describe("16 bytes")); // not binary data
Float64Array with 2 items
DataView over 8 bytes
ArrayBuffer of 16 bytes
not binary data
How It Works
Test DataView first. Both kinds of view pass isView, so the more specific instanceof DataView check has to run before it.
Typed arrays count items, not bytes. 16 bytes hold two 8-byte numbers, so the Float64Array has length 2 while its byteLength is 16.
Fall through safely. The buffer itself and the string fail isView, landing in the ArrayBuffer branch and the default answer.
Compatibility
Browser & Runtime Support
ArrayBuffer.isView() arrived with typed arrays and DataView in ES2015 (ES6).
✓ Baseline · ES2015
ArrayBuffer.isView()
Supported in every modern browser, plus Node.js, Deno, and Bun.
98%Modern browser support
Google ChromeAll modern versions
Full support
Mozilla FirefoxAll modern versions
Full support
Apple SafariAll modern versions
Full support
Microsoft EdgeAll modern versions
Full support
Node.jsAll current releases
Supported
DenoAll releases
Supported
Internet ExplorerRetired · not a modern target
Legacy
ArrayBuffer.isView()Excellent
Bottom line: Safe everywhere modern JavaScript runs. In Node.js a Buffer is a Uint8Array subclass, so ArrayBuffer.isView(buf) is true for it as well.
Frequently Asked Questions
It returns true for any typed array (Uint8Array, Float32Array, and so on) or DataView, and false for everything else, including the ArrayBuffer itself.
An ArrayBuffer is the raw memory, not a view of it. You cannot read its bytes directly; you create a typed array or DataView first. To test for a raw buffer, use value instanceof ArrayBuffer.
Always ArrayBuffer.isView(value): it is static, like Array.isArray. Buffers and typed arrays have no isView method.
Use new Uint8Array(view.buffer, view.byteOffset, view.byteLength). A view can start in the middle of its buffer or cover only part of it, so view.buffer alone may include extra bytes.
Yes. A Node.js Buffer extends Uint8Array, so ArrayBuffer.isView(Buffer.from("hi")) is true.