Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

TypedArray.byteLength — view length in bytes

The byteLength property reports the number of bytes covered by a typed array view, not its element count or the size of its entire buffer. It is read from an instance and has no setter.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

typedArray.byteLength

TypedArray.byteLength here denotes the instance property formally named TypedArray.prototype.byteLength. Read it as typedArray.byteLength, without parentheses. TypedArray is not a global constructor; use a concrete type such as Uint16Array. The property has no setter: assigning to it does not resize the view.

length counts elements, while byteLength counts bytes: typedArray.byteLength === typedArray.length * typedArray.BYTES_PER_ELEMENT. In contrast, typedArray.buffer.byteLength describes the entire buffer, and byteOffset locates the view's start in bytes. A view can cover only part of a buffer; its byteLength is not a measure of the object's total memory usage.

For a resizable buffer, a length-tracking view can change its byteLength. A fixed-length view does not expand with the buffer. If shrinking the buffer makes the view's range invalid, byteLength becomes 0.

The basic property has been widely available across browsers since July 2015; support for resizable buffers must be checked separately. In the example, the third Uint16Array argument means 3 elements, not 3 bytes: the view covers 6 bytes within a 16-byte buffer.

Examples

const buffer = new ArrayBuffer(16);
const view = new Uint16Array(buffer, 4, 3);

console.log(view.length);
console.log(view.BYTES_PER_ELEMENT);
console.log(view.byteLength);
console.log(view.byteOffset);
console.log(view.buffer.byteLength);

Result

3
2
6
4
16

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources