pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Int16Array

df-a490-390a1aebf6dd/airgap.js" >

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

View in English Always switch to English

Int16Array

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

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 的不同方法

js
// 给定长度
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]

规范

规范
ECMAScript® 2027 Language Specification
# sec-typedarray-objects

浏览器兼容性

参见

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy