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 |
瀏覽器相容性
載入中…