JavaScript ArrayBuffer isView() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
ArrayBuffer

Definition

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)
CallWhat 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

ParameterDescription
valueAny value to test. If you leave it out it is undefined, and the answer is false.

Return Value

Return ValueDescription
booleantrue 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.

JavaScript
const buffer = new ArrayBuffer(8);
const bytes = new Uint8Array(buffer);
const view = new DataView(buffer);

console.log(ArrayBuffer.isView(bytes));      // true
console.log(ArrayBuffer.isView(view));       // true
console.log(ArrayBuffer.isView(buffer));     // false
console.log(ArrayBuffer.isView([1, 2, 3]));  // false
console.log(ArrayBuffer.isView(null));       // false
Try It Yourself

How It Works

  1. One buffer, two views. bytes and view both look at the same 8 bytes of buffer; creating them copies nothing.
  2. Views answer true. Typed arrays and DataView are the two kinds of view, so the first two checks print true.
  3. 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
}
Try It Yourself

How It Works

  1. 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.
  2. Raw buffers second. An ArrayBuffer fails isView, so the instanceof ArrayBuffer branch wraps all of its bytes.
  3. 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
Try It Yourself

How It Works

  1. Test DataView first. Both kinds of view pass isView, so the more specific instanceof DataView check has to run before it.
  2. Typed arrays count items, not bytes. 16 bytes hold two 8-byte numbers, so the Float64Array has length 2 while its byteLength is 16.
  3. Fall through safely. The buffer itself and the string fail isView, landing in the ArrayBuffer branch and the default answer.

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 Chrome All modern versions
Full support
Mozilla Firefox All modern versions
Full support
Apple Safari All modern versions
Full support
Microsoft Edge All modern versions
Full support
Node.js All current releases
Supported
Deno All releases
Supported
Internet Explorer Retired · 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.

Next: resize()

Grow or shrink a resizable buffer in place, without copying bytes by hand.

resize() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful