JavaScript DataView Object
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
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.
Desktop





Tablets & Mobile





