getUint8() reads one byte from a DataView and returns it as an unsigned whole number from 0 to 255. “Unsigned” means the number can never be negative: all 8 bits count toward the value. This is the most natural way to look at raw data, because a byte is usually described as a value from 0 to 255 (or 00 to ff in hexadecimal, base 16). Pass the byte offset: the position of the byte, counted from 0 at the start of the view.
Call getUint8() on a DataView object with the position of the byte you want.
JavaScript
dataview.getUint8(byteOffset)
Call
What it does
view.getUint8(byteOffset)
Reads the single byte at byteOffset and returns an unsigned whole number (never negative) from 0 to 255.
view.getUint8(i).toString(16)
Reads byte i and shows it in hexadecimal (base 16), the usual way to look at raw bytes.
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 getUint8() has no littleEndian argument.
Library declarations
JavaScript
DataView.prototype.getUint8(byteOffset)
// returns a Number: 0 to 255
// reads 1 byte starting at byteOffset (counted from the start of the view)
// needs byteOffset < view.byteLength, else RangeError
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. It must be smaller than view.byteLength. A negative or too-large offset throws a RangeError.
Return Value
Return Value
Description
Number
A whole Number from 0 to 255, built from the 1 byte at byteOffset. It is never negative.
JavaScript Examples
Example 1 — Read the Colour of One Pixel
Image data often stores a pixel as four bytes: red, green, blue and alpha (opacity). Read them and build a CSS colour.
JavaScript
const pixel = new DataView(new Uint8Array([255, 128, 0, 200]).buffer);
const r = pixel.getUint8(0);
const g = pixel.getUint8(1);
const b = pixel.getUint8(2);
const a = pixel.getUint8(3);
console.log("rgb(" + r + ", " + g + ", " + b + ")"); // rgb(255, 128, 0)
console.log("alpha: " + (a / 255).toFixed(2)); // alpha: 0.78
Text becomes bytes.TextEncoder turns "Hi!" into its UTF-8 bytes. Passing bytes.byteOffset and bytes.byteLength gives the view exactly the same window.
Hex for every byte. The loop reads each byte with getUint8(), converts it to base 16 and pads it to two digits: H is 48, i is 69 and ! is 21.
Stop before byteLength. The last valid offset is byteLength - 1. Asking for offset byteLength throws a RangeError.
Compatibility
Browser & Runtime Support
getUint8() has been part of JavaScript since ES2015, when DataView itself was standardised.
✓ ES2015 · Baseline
DataView.prototype.getUint8()
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
getUint8()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
A whole number from 0 to 255: the value of the byte at the offset you pass, read without a sign.
Call toString(16) on the number and pad it to two characters: view.getUint8(0).toString(16).padStart(2, "0") gives "0a" for the value 10.
For a valid index, yes. The differences are that getUint8() counts from the view start, works on a DataView that mixes types, and throws a RangeError past the end instead of returning undefined.
It reads a single byte, and one byte has no order to swap. Extra arguments are simply ignored.
No. All 8 bits count as value, so the smallest result is 0. Use getInt8() if the byte stores a signed number.