setInt8() writes one byte into a DataView, treating your number as a signed 8-bit integer (a whole number from -128 to 127). You pass the byte offset first and the value second. Values that do not fit are not rejected: the fraction is dropped and the number wraps around, so 200 is stored as -56. The method returns undefined; you see the change when you read the byte back.
Call setInt8() on a DataView object with a byte position and the value to write.
JavaScript
dataview.setInt8(byteOffset, value)
Call
What it does
view.setInt8(byteOffset, value)
Converts value to a signed 8-bit integer (-128 to 127) and writes it into the byte at byteOffset. Returns undefined.
view.setInt8(i, view.getInt8(i) - 1)
Subtracts 1 from a signed byte in place; -128 minus 1 wraps around to 127.
Part of the original DataView from ES2015, so every modern browser and runtime has it. With one byte there is no byte order to choose, so setInt8() has no littleEndian argument.
Library declarations
JavaScript
DataView.prototype.setInt8(byteOffset, value)
// returns undefined; writes 1 byte starting at byteOffset
// value is converted to a signed 8-bit integer
// needs byteOffset < view.byteLength, else RangeError
Parameters
Parameter
Description
byteOffset
Where to start writing, 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. It must be smaller than view.byteLength. A negative or too-large offset throws a RangeError.
value
The number to store. It is converted to a Number, the fraction is cut off (3.9 becomes 3, -3.9 becomes -3), and the result wraps around modulo 256 into -128 to 127. NaN and Infinity are stored as 0.
Return Value
Return Value
Description
undefined
setInt8() gives nothing back. Its result is the 1 byte it changed inside the buffer; read them back with getInt8().
JavaScript Examples
Example 1 — Save Positive and Negative Score Changes
A game saves each round’s score change in one signed byte. Write four changes and look at the raw bytes.
A header byte first. Byte 0 holds 0xa1 (161), a made-up code that says “this packet is joystick data”.
A second view for the axes.new DataView(packet, 1) starts at buffer byte 1, so axes.setInt8(0, ...) writes buffer byte 1, not byte 0.
Signed axis values. A stick can lean left or right, so negative numbers make sense: -100 is stored as the byte 156 and read back as -100.
Compatibility
Browser & Runtime Support
setInt8() has been part of JavaScript since ES2015, when DataView itself was standardised.
✓ ES2015 · Baseline
DataView.prototype.setInt8()
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
setInt8()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
It returns undefined. The method only changes one byte in the buffer; read it back with getInt8() to see the stored value.
The value wraps around: 200 minus 256 is -56, so getInt8() later returns -56 and getUint8() returns 200.
No, it cuts them off toward zero. 127.9 is stored as 127 and -3.7 as -3.
Only because of the offset. A negative offset, or one that is not smaller than the view byteLength, throws a RangeError. Values never throw; they are converted.
For raw bytes such as file data or colours, setUint8() is clearer because you think in 0 to 255. Use setInt8() when the byte really means a small signed number, such as a change of -5.