Movatterモバイル変換


[0]ホーム

URL:


  1. 面向开发者的 Web 技术
  2. JavaScript
  3. JavaScript 参考
  4. JavaScript 标准内置对象
  5. TypedArray
  6. TypedArray.prototype.length

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in EnglishAlways switch to English

TypedArray.prototype.length

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

TypedArray 实例的length 访问器属性返回该类型化数组的长度(以元素为单位)。

尝试一下

// Create an ArrayBuffer with a size in bytesconst buffer = new ArrayBuffer(8);const uint8 = new Uint8Array(buffer, 2);console.log(uint8.length);// Expected output: 6

描述

length 属性是一个 set 访问器函数为undefined 的访问器属性,这意味着你只能读取该属性。该值在构建TypedArray 时确定,不可更改。如果TypedArray 没有指定byteOffsetlength,则将返回引用的ArrayBuffer 的长度。TypedArrayTypedArray 对象之一。

示例

使用length 属性

js
const buffer = new ArrayBuffer(8);let uint8 = new Uint8Array(buffer);uint8.length; // 8(与缓冲区 length 相匹配)uint8 = new Uint8Array(buffer, 1, 5);uint8.length; // 5(在构造 Uint8Array 时指定)uint8 = new Uint8Array(buffer, 2);uint8.length; // 6(根据被构造的 Uint8Array 的偏移量)

规范

Specification
ECMAScript® 2026 Language Specification
# sec-get-%typedarray%.prototype.length

浏览器兼容性

参见

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp