Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

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

Int32Array

BaselineWidely available

Int32Array 类型表示在平台顺序字节中一个双补码 32 位有符号的整型数组。如果需要控制字节顺序,请改用DataView。此内容的初始化为0。一旦创建,你可以使用对象的方法或者标准数组索引的语法 (即使用括号表示法)。

语法

new Int32Array(length);new Int32Array(typedArray);new Int32Array(object);new Int32Array(buffer [, byteOffset [, length]]);

更多关于构造函数语法和参数的详细信息,请参阅*TypedArray。*

静态属性

Int32Array.BYTES_PER_ELEMENT

Returns a number value of the element size.4 in the case of anInt32Array.

Int32Array.length

Static length property whose value is 3. For the actual length (number of elements), seeInt32Array.prototype.length.

Int32Array.prototype

Prototype for theTypedArray objects.

静态方法

Int32Array.from()

从类似数组或者可迭代对象中创建一个新的Int32Array。另见Array.from().

Int32Array.of()

创建一个新的具有可变数量参数的Int32Array。另见Array.of()

实例属性

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

Int32Array.prototype.constructor

返回创建实例原型的函数。默认情况下,它是Int32Array 的构造函数。

Int32Array.prototype.buffer只读

返回在构造时被固定的Int32Array 引用的ArrayBuffer,因此只读。

Int32Array.prototype.byteLength只读

返回从其ArrayBuffer 开始的Int32Array 长度的 (以字节为单位)。在构造时被固定,因此只读。

Int32Array.prototype.byteOffset只读

返回从其ArrayBuffer 开始的偏移量 (以字节为单位)。在构造时被固定,因此只读。

Int32Array.prototype.length只读

返回Int32ArrayInt32Array 包含的元素个数。在构造时被固定,因此只读。

实例方法

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

示例

不同的方式创建一个Int32Array

js
// 从一个数字var int32 = new Int32Array(2);int32[0] = 42;console.log(int32[0]); // 42console.log(int32.length); // 2console.log(int32.BYTES_PER_ELEMENT); // 4// 从一个数组var arr = new Int32Array([21, 31]);console.log(arr[1]); // 31// 从一个其他 TypedArrayvar x = new Int32Array([21, 31]);var y = new Int32Array(x);console.log(y[0]); // 21// 从一个 ArrayBuffervar buffer = new ArrayBuffer(16);var z = new Int32Array(buffer, 0, 4);

规范

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

浏览器兼容性

兼容性说明

Starting with ECMAScript 2015 (ES6),In32Array constructors require to be constructed with anew operator. Calling aInt32Array constructor as a function withoutnew, will throw aTypeError from now on.

js
var dv = Int32Array([1, 2, 3]);// TypeError: calling a builtin Int32Array constructor// without new is forbidden
js
var dv = new Int32Array([1, 2, 3]);

参见

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp