DataView.prototype.getUint8()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
getUint8()
方法从 DataView
相对于起始位置偏移 n 个字节处开始,获取一个无符号的 8-bit 整数 (一个字节).
尝试一下
// Create an ArrayBuffer with a size in bytes
const buffer = new ArrayBuffer(16);
const view = new DataView(buffer);
view.setUint8(1, 255); // Max unsigned 8-bit integer
console.log(view.getUint8(1));
// Expected output: 255
语法
dataview.getUint8(byteOffset)
参数
- byteOffset
-
偏移量,单位为字节,从头开始计算。
抛出错误
RangeError
-
如果 byteOffset 超出了视图能储存的值,就会抛出错误。
描述
没有对齐约束; 多字节值可以从任何偏移量获取。
示例
js
var buffer = new ArrayBuffer(8);
var dataview = new DataView(buffer);
dataview.getUint8(1); // 0
规范
Specification |
---|
ECMAScript® 2025 Language Specification # sec-dataview.prototype.getuint8 |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getUint8 |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.