A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Int16Array below:

Int16Array - JavaScript | MDN

Int16Array

Baseline Widely available

Int16Array 类型化数组表示按平台字节顺序排列的 16 位有符号整数数组。如果需要控制字节顺序,请使用 DataView 代替。数组内容初始化为 0。建立后,可以使用对象的方法或标准数组索引语法(即使用方括号表示法)引用数组中的元素。

Int16Array 是隐藏类 TypedArray 的子类。

构造函数
Int16Array()

创建一个新的 Int16Array 对象。

静态属性

从父对象 TypedArray 继承静态属性。

Int16Array.BYTES_PER_ELEMENT

返回元素大小的数值。在 Int16Array 中该值为 2。

静态方法

从父对象 TypedArray 继承静态方法。

实例属性

从父对象 TypedArray 继承实例属性。

这些属性在 Int16Array.prototype 中定义,并为所有 Int16Array 实例共享。

Int16Array.prototype.BYTES_PER_ELEMENT

返回元素大小的数值。在 Int16Array 中该值为 2。

Int16Array.prototype.constructor

创建实例对象的构造函数。对于 Int16Array 实例,初始值是 Int16Array 构造函数。

实例方法

从父对象 TypedArray 继承实例方法。

示例 创建 Int16Array 的不同方法
// 给定长度
const int16 = new Int16Array(2);
int16[0] = 42;
console.log(int16[0]); // 42
console.log(int16.length); // 2
console.log(int16.BYTES_PER_ELEMENT); // 2

// 从一个数组
const x = new Int16Array([21, 31]);
console.log(x[1]); // 31

// 从另外一个 TypedArray
const y = new Int16Array(x);
console.log(y[0]); // 21

// 从一个 ArrayBuffer
const buffer = new ArrayBuffer(16);
const z = new Int16Array(buffer, 2, 4);
console.log(z.byteOffset); // 2

// 从可迭代对象
const iterable = (function* () {
  yield* [1, 2, 3];
})();
const int16FromIterable = new Int16Array(iterable);
console.log(int16FromIterable);
// Int16Array [1, 2, 3]
规范 浏览器兼容性 参见

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4