Favorites

JavaScript DataView Object

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
DataView
JavaScript Structured Data · ConstructorThis object is supported by all modern browsers.
Updated 28th November 2026

A DataView reads and writes numbers of different types at any position in an ArrayBuffer, with control over byte order. It is used to parse binary file formats.

Description

A DataView provides a low-level interface for reading and writing multiple number types in an ArrayBuffer, at any byte offset. Methods such as getUint16(), setFloat32() and getBigInt64() each take an offset and an optional littleEndian flag.

That control over byte order (endianness) is the main reason to use it instead of a typed array, which always uses the computer's native order. It suits parsing binary formats, such as image headers or network packets, that mix fields of different sizes.

Most file formats and network protocols specify the byte order of their numbers, which is why DataView asks for it on every call. A DataView can also be limited to part of a buffer by passing a byte offset and length when you create it, so you can treat a slice of a larger file as its own record. Reading past the end of the view throws a RangeError.

Creating

new DataView(buffer)
new DataView(buffer, byteOffset, byteLength)

Example

const buffer = new ArrayBuffer(6);
const view = new DataView(buffer);

view.setUint16(0, 500);          // big-endian by default
view.setFloat32(2, 3.5, true);   // little-endian

console.log(view.getUint16(0));
console.log(view.getFloat32(2, true));
console.log(new Uint8Array(buffer));

Browser Support

The following information will show you the current browser support for the DataView object. Hover over a browser icon to see the version that first introduced support for this object.

This object is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee