TypedArray.prototype.byteOffset

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.

TypedArray 实例的 byteOffset 访问器属性返回该类型化数组相对于其 ArrayBufferSharedArrayBuffer 开始位置的偏移量(以字节为单位)。

描述

byteOffset 属性是一个访问器属性,其设置访问器函数为 undefined,意味着该属性只能读取。该值在构造 TypedArray 时确定,并且不能被更改。TypedArray类型化数组对象之一。

示例

使用 byteOffset 属性

js
const buffer = new ArrayBuffer(8);

const uint8array1 = new Uint8Array(buffer);
uint8array1.byteOffset; // 0(未指定偏移量)

const uint8array2 = new Uint8Array(buffer, 3);
uint8array2.byteOffset; // 3(在构造 Uint8Array 时指定)

规范

Specification
ECMAScript Language Specification
# sec-get-%typedarray%.prototype.byteoffset

浏览器兼容性

BCD tables only load in the browser

参见