JavaScript DataView Methods

About This Index
This page is the JavaScript DataView Methods index for the tutorial track. Each row links to a full guide with syntax, three runnable examples, browser notes, and FAQs.
Learn what a DataView is and when to use it on /js/dataview. Use this page when you need one specific method, such as getUint8(), setUint16(), or getFloat32().
Every number type has a get method that reads bytes and a set method that writes them. The name tells you the type and its size in bits: getInt16() reads a signed 16-bit (2-byte) whole number, setFloat64() writes an 8-byte decimal number. All of them are instance methods, so you call them on a view: view.getInt16(0).
How to Call a DataView Method
The first argument is always the byte offset: the position of the first byte, counted from the start of the view. Setters take the value second. Methods for 2 or more bytes accept a last littleEndian argument that picks the byte order (the default is big-endian):
const view = new DataView(new ArrayBuffer(8));
// write 2 bytes at offset 0, then read them back
view.setInt16(0, -300);
view.getInt16(0); // -300
// 4 bytes at offset 2, least significant byte first
view.setUint32(2, 4000000000, true);
view.getUint32(2, true); // 4000000000
view.getUint32(2); // 2649070
// a 4-byte float at offset 4
view.setFloat32(4, 1.5);
view.getFloat32(4); // 1.5 Which Type Do I Need?
Pick the smallest type that can hold your values. “Int” types can be negative, “Uint” types (unsigned) start at 0, and “Float” types hold decimals.
| Type | Bytes | Values | Read / write |
|---|---|---|---|
| Int8 | 1 | -128 to 127 | getInt8() / setInt8() |
| Uint8 | 1 | 0 to 255 | getUint8() / setUint8() |
| Int16 | 2 | -32768 to 32767 | getInt16() / setInt16() |
| Uint16 | 2 | 0 to 65535 | getUint16() / setUint16() |
| Int32 | 4 | -2147483648 to 2147483647 | getInt32() / setInt32() |
| Uint32 | 4 | 0 to 4294967295 | getUint32() / setUint32() |
| BigInt64 | 8 | -9223372036854775808n to 9223372036854775807n | getBigInt64() / setBigInt64() |
| BigUint64 | 8 | 0n to 18446744073709551615n | getBigUint64() / setBigUint64() |
| Float16 (new) | 2 | about ±65504, about 3 digits | getFloat16() / setFloat16() |
| Float32 | 4 | about ±3.4028234663852886e38, about 7 digits | getFloat32() / setFloat32() |
| Float64 | 8 | about ±1.7976931348623157e308, about 15 to 17 digits | getFloat64() / setFloat64() |
JavaScript DataView Methods Table
All method guides in this JavaScript tutorial series (22 tutorials), grouped by what they do.
Read whole numbers (get)
6 methodsRead 1, 2, or 4 bytes as a whole number. The Int methods allow negative numbers; the Uint methods start at 0.
| Method | Description | Tutorial |
|---|---|---|
getInt8() | Read one byte as a signed whole number from -128 to 127. | Open |
getUint8() | Read one byte as an unsigned whole number from 0 to 255. | Open |
getInt16() | Read 2 bytes as a signed whole number from -32768 to 32767. | Open |
getUint16() | Read 2 bytes as an unsigned whole number from 0 to 65535. | Open |
getInt32() | Read 4 bytes as a signed whole number from -2147483648 to 2147483647. | Open |
getUint32() | Read 4 bytes as an unsigned whole number from 0 to 4294967295. | Open |
Read big numbers (get)
2 methodsRead 8 bytes as a 64-bit whole number. These return a BigInt, such as 42n.
| Method | Description | Tutorial |
|---|---|---|
getBigInt64() | Read 8 bytes as a signed 64-bit whole number (returns a BigInt). | Open |
getBigUint64() | Read 8 bytes as an unsigned 64-bit whole number (returns a BigInt). | Open |
Read decimals (get)
3 methodsRead 2, 4, or 8 bytes as a floating point number (a number with a fraction).
| Method | Description | Tutorial |
|---|---|---|
getFloat16() | Read 2 bytes as a 16-bit (half precision) floating point number. New in ES2025. | Open |
getFloat32() | Read 4 bytes as a 32-bit (single precision) floating point number. | Open |
getFloat64() | Read 8 bytes as a 64-bit (double precision) floating point number, the JavaScript Number format. | Open |
Write whole numbers (set)
6 methodsWrite a whole number into 1, 2, or 4 bytes. Fractions are cut off and too-big values wrap around.
| Method | Description | Tutorial |
|---|---|---|
setInt8() | Write one byte as a signed whole number; out-of-range values wrap around. | Open |
setUint8() | Write one byte as an unsigned whole number from 0 to 255; values wrap around. | Open |
setInt16() | Write a signed 16-bit whole number into 2 bytes, big- or little-endian. | Open |
setUint16() | Write an unsigned 16-bit whole number into 2 bytes; wraps at 65536. | Open |
setInt32() | Write a signed 32-bit whole number into 4 bytes; decimals are truncated. | Open |
setUint32() | Write an unsigned 32-bit whole number into 4 bytes; wraps at 4294967296. | Open |
Write big numbers (set)
2 methodsWrite a BigInt into 8 bytes. A plain Number throws a TypeError.
| Method | Description | Tutorial |
|---|---|---|
setBigInt64() | Write a signed 64-bit BigInt into 8 bytes; Numbers throw a TypeError. | Open |
setBigUint64() | Write an unsigned 64-bit BigInt into 8 bytes; wraps around at 2^64. | Open |
Write decimals (set)
3 methodsWrite a number into 2, 4, or 8 bytes of floating point. Smaller types round the value.
| Method | Description | Tutorial |
|---|---|---|
setFloat16() | Write a number as a 16-bit (half precision) float; rounds to about 3 digits. New in ES2025. | Open |
setFloat32() | Write a number as a 32-bit (single precision) float; rounds to about 7 digits. | Open |
setFloat64() | Write a number as a 64-bit (double precision) float; stored exactly, no rounding. | Open |
Frequently Asked Questions
Start with getBigInt64()
The first guide in the list: read 8 bytes as one exact 64-bit whole number.
14 people found this page helpful
