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 开头的偏移量(以字节为单位)。

¥The byteOffset accessor property of TypedArray instances returns the offset (in bytes) of this typed array from the start of its ArrayBuffer or SharedArrayBuffer.

描述

¥Description

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

¥The byteOffset property is an accessor property whose set accessor function is undefined, meaning that you can only read this property. The value is established when a TypedArray is constructed and cannot be changed. TypedArray is one of the TypedArray objects.

示例

¥Examples

使用 byteOffset 属性

¥Using the byteOffset property

js
const buffer = new ArrayBuffer(8);

const uint8array1 = new Uint8Array(buffer);
uint8array1.byteOffset; // 0 (no offset specified)

const uint8array2 = new Uint8Array(buffer, 3);
uint8array2.byteOffset; // 3 (as specified when constructing Uint8Array)

规范

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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看