getInt16() reads two bytes from a DataView and returns them as a signed 16-bit whole number from -32768 to 32767. Because the number is spread over two bytes, their order matters. This is called endianness: big-endian puts the most significant (“biggest”) byte first, little-endian puts the least significant byte first. getInt16() reads big-endian unless you pass true as the second argument.
Reads the 2 bytes starting at byteOffset in big-endian order (most significant byte first) and returns a signed whole number from -32768 to 32767.
view.getInt16(byteOffset, true)
Reads the same 2 bytes in little-endian order (least significant byte first), the order used by most file formats from PCs, such as WAV and BMP.
Part of the original DataView from ES2015, so every modern browser and runtime has it. Unlike a Int16Array, a DataView has no alignment rule: getInt16() works at any byte position, even one that is not a multiple of 2.
Library declarations
JavaScript
DataView.prototype.getInt16(byteOffset)
DataView.prototype.getInt16(byteOffset, littleEndian)
// returns a Number: -32768 to 32767
// reads 2 bytes starting at byteOffset (counted from the start of the view)
// needs byteOffset + 2 <= view.byteLength, else RangeError
// littleEndian: false or left out = big-endian
Parameters
Parameter
Description
byteOffset
Where to start reading, counted in bytes from the start of the view (not of the underlying buffer). It is converted to a whole number, so 1.9 means 1 and "2" means 2. All 2 bytes must fit: byteOffset + 2 may not be larger than view.byteLength. A negative or too-large offset throws a RangeError.
littleEndian
Optional. Leave it out (or pass false) for big-endian: the most significant of the 2 bytes comes first. Pass true for little-endian: the least significant byte comes first. Any truthy value, such as 1, also means little-endian.
Return Value
Return Value
Description
Number
A whole Number from -32768 to 32767, built from the 2 bytes at byteOffset using two’s complement for negative values.
JavaScript Examples
Example 1 — Find the Loudest Sample in 16-bit Audio
CD-quality audio stores every sample as a signed 16-bit number. Read four little-endian samples and find the loudest one.
JavaScript
const samples = new DataView(new ArrayBuffer(8));
samples.setInt16(0, 1200, true);
samples.setInt16(2, -9000, true);
samples.setInt16(4, 4500, true);
samples.setInt16(6, -300, true);
let peak = 0;
for (let i = 0; i < samples.byteLength; i += 2) {
peak = Math.max(peak, Math.abs(samples.getInt16(i, true)));
}
console.log("peak: " + peak); // peak: 9000
console.log("loudness: " + (peak / 32768 * 100).toFixed(1) + "%"); // loudness: 27.5%
A number at an odd position. Byte 0 (0x07) is a 1-byte field, so the 16-bit value starts at offset 1.
DataView does not care about alignment. getInt16(1) reads the bytes fe 0c and returns -500 without complaint.
A typed array refuses. An Int16Array must start at an even byte offset, so creating one at offset 1 throws a RangeError. That is a key reason to use DataView for file formats.
Compatibility
Browser & Runtime Support
getInt16() has been part of JavaScript since ES2015, when DataView itself was standardised.
✓ ES2015 · Baseline
DataView.prototype.getInt16()
Works in every modern browser and in Node.js, Deno and Bun. It runs on a normal ArrayBuffer, so no special page setup is needed.
100%Modern browser support
Google ChromeModern versions · Desktop & Mobile
Full support
Mozilla FirefoxModern versions · Desktop & Mobile
Full support
Apple SafariModern versions · macOS & iOS
Full support
Microsoft EdgeModern versions · Chromium
Full support
OperaModern versions
Full support
Samsung InternetModern versions · Android
Full support
Internet ExplorerRetired browser · not tested here
Legacy
Node.jsCurrent releases · checked on Node 24
Supported
DenoCurrent releases
Supported
BunCurrent releases
Supported
getInt16()All modern engines
Bottom line: Safe to use without a fallback. It also works on a SharedArrayBuffer, but a normal ArrayBuffer is all you need.
Frequently Asked Questions
From -32768 to 32767. Two bytes hold 65536 patterns, and half of them are used for negative numbers.
It is the order of the two bytes. Big-endian (the default) puts the high byte first; little-endian, chosen with true, puts the low byte first.
WAV samples are little-endian. Call getInt16(offset, true); without true the bytes are read the wrong way round.
Yes. DataView has no alignment rule, so getInt16(1) or getInt16(3) work as long as both bytes are inside the view.
They read the same two bytes. getInt16() returns -32768 to 32767, getUint16() returns 0 to 65535, so 0xffff is -1 for one and 65535 for the other.