Uint32Array
Uint32Array 类型化数组代表一个平台字节序中的 32 位无符号整数数组。如果需要控制字节序,请使用 DataView。除非明确提供了初始化数据,否则内容将初始化为 0。一旦建立,您就可以使用对象的方法或标准的数组索引语法(即使用方括号表示法)来引用数组中的元素。
Uint32Array 是隐藏的 TypedArray 类的子类。
构造函数
Uint32Array()-
创建一个新的
Uint32Array对象。
静态属性
也继承了其父类 TypedArray 的静态属性.
Uint32Array.BYTES_PER_ELEMENT-
返回一个数值,表示元素大小。对于
Uint32Array,其值为4。
静态方法
继承了其父类 TypedArray 的静态方法.
实例属性
也继承了其父类 TypedArray 的实例属性.
这些属性定义在 Uint32Array.prototype 上,并由所有 Uint32Array 实例共享。
Uint32Array.prototype.BYTES_PER_ELEMENT-
返回一个数值,表示元素大小。对于
Uint32Array,其值为4。 Uint32Array.prototype.constructor-
创建实例对象的构造函数。对于
Uint32Array实例,其初始值为Uint32Array构造函数。
实例方法
继承了其父类 TypedArray 的实例方法.
示例
创建 Uint32Array 的不同方法
js
// From a length
const uint32 = new Uint32Array(2);
uint32[0] = 42;
console.log(uint32[0]); // 42
console.log(uint32.length); // 2
console.log(uint32.BYTES_PER_ELEMENT); // 4
// From an array
const x = new Uint32Array([21, 31]);
console.log(x[1]); // 31
// From another TypedArray
const y = new Uint32Array(x);
console.log(y[0]); // 21
// From an ArrayBuffer
const buffer = new ArrayBuffer(32);
const z = new Uint32Array(buffer, 4, 4);
console.log(z.byteOffset); // 4
// From an iterable
const iterable = (function* () {
yield* [1, 2, 3];
})();
const uint32FromIterable = new Uint32Array(iterable);
console.log(uint32FromIterable);
// Uint32Array [1, 2, 3]
规范
| 规范 |
|---|
| ECMAScript® 2026 语言规范 # sec-typedarray-objects |
浏览器兼容性
加载中…