Movatterモバイル変換


[0]ホーム

URL:


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

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

View in EnglishAlways switch to English

Uint32Array

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月⁩.

Uint32Array 表示一个由基于平台字节序的 32 位无符号字节组成的数组。如果需要对字节顺序进行控制 (译者注:即 littleEndian 或 bigEndian),请使用DataView 代替。数组中每个元素的初始值都是0。一旦创建,你可以用对象的方法引用数组里的元素,或者使用标准的数组索引语法(即,使用中括号)。

语法

new Uint32Array(); // new in ES2017new Uint32Array(length);new Uint32Array(typedArray);new Uint32Array(object);new Uint32Array(buffer [, byteOffset [, length]]);

更多的构造器语法和属性请参照TypedArray

静态属性

Uint32Array.BYTES_PER_ELEMENT

返回一个数值,代表Uint32Array中单个元素的字节大小。Uint32Array 返回4

Uint32Array.length

固定值 (static) 属性,值为 3。使用Uint32Array.prototype.length 获得数组的真实长度(元素个数)。

Uint32Array.prototype

TypedArray 对象的原型链。

静态方法

Uint32Array.from()

从类似数组或者可迭代对象创建一个新的Uint32Array。请参考Array.from()

Uint32Array.of()

从可变长度的参数创建一个新的Uint32Array。请参考Array.of()

实例属性

还从其父接口TypedArray 继承实例属性。

Uint32Array.prototype.constructor

返回创建实例原型的函数。默认返回Uint32Array 的构造器。

Uint32Array.prototype.buffer只读

返回Uint32Array引用的ArrayBuffer。由于构造时已固定,所以是只读的

Uint32Array.prototype.byteLength只读

返回从其ArrayBuffer 开始的Uint32Array 字节长度。由于构造时已固定,所以是只读的

Uint32Array.prototype.byteOffset只读

返回从其ArrayBuffer 的偏移开始的Uint32Array 字节长度。由于构造时已固定,所以是只读的

Uint32Array.prototype.length只读

返回Uint32Array 中元素的个数。由于构造时已固定,所以是只读的

实例方法

从其父接口TypedArray 继承实例方法。

示例

用不同的方法创建Uint32Array

js
// 给定长度var uint32 = new Uint32Array(2);uint32[0] = 42;console.log(uint32[0]); // 42console.log(uint32.length); // 2console.log(uint32.BYTES_PER_ELEMENT); // 4// 给定数组var arr = new Uint32Array([21, 31]);console.log(arr[1]); // 31// 给定 TypedArrayvar x = new Uint32Array([21, 31]);var y = new Uint32Array(x);console.log(y[0]); // 21// 给定 ArrayBuffervar buffer = new ArrayBuffer(16);var z = new Uint32Array(buffer, 0, 4);// 给定可迭代对象var iterable = (function* () {  yield* [1, 2, 3];})();var uint32 = new Uint32Array(iterable);// Uint32Array[1, 2, 3]

规范

Specification
ECMAScript® 2026 Language Specification
# sec-typedarray-objects

浏览器兼容性

参见

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp