Int8Array
类型数组表示二进制补码8位有符号整数的数组。内容初始化为0。 一旦建立,你可以使用对象的方法引用数组中的元素,或使用标准数组索引语法( 即,使用括号注释)。
new Int8Array(length);
new Int8Array(typedArray);
new Int8Array(object);
new Int8Array(buffer [, byteOffset [, length]]);
有关构造函数语法和参数的更多信息,请访问 TypedArray.
Int8Array.BYTES_PER_ELEMENT
Int8Array中这个值为1
.Int8Array.prototype.length
获得获取数组内元素个数方法。Int8Array.name
Int8Array.prototype
Int8Array.from()
Array.from()
.Int8Array.of()
Array.of()
.Int8Array
原型方法所有 Int8Array对象都继承自 %TypedArray%.prototype
.
Int8Array.prototype.constructor
Int8Array构造函数
.Int8Array.prototype.buffer
只读 ArrayBuffer
referenced by the Int8Array
Fixed at construction time and thus read only.Int8Array.prototype.byteLength
只读 Int8Array
from the start of its ArrayBuffer
. Fixed at construction time and thus read only.Int8Array.prototype.byteOffset
只读 Int8Array
from the start of its ArrayBuffer
. Fixed at construction time and thus read only.Int8Array.prototype.length
只读 Int8Array
. Fixed at construction time and thus read only.Int8Array.prototype.copyWithin()
Array.prototype.copyWithin()
.Int8Array.prototype.entries()
Array Iterator
object that contains the key/value pairs for each index in the array. See also Array.prototype.entries()
.Int8Array.prototype.every()
Array.prototype.every()
.Int8Array.prototype.fill()
Array.prototype.fill()
.Int8Array.prototype.filter()
Array.prototype.filter()
.Int8Array.prototype.find()
undefined
if not found. See also Array.prototype.find()
.Int8Array.prototype.findIndex()
Array.prototype.findIndex()
.Int8Array.prototype.forEach()
Array.prototype.forEach()
.Int8Array.prototype.includes()
true
or false
as appropriate. See also Array.prototype.includes()
.Int8Array.prototype.indexOf()
Array.prototype.indexOf()
.Int8Array.prototype.join()
Array.prototype.join()
.Int8Array.prototype.keys()
Array Iterator
that contains the keys for each index in the array. See also Array.prototype.keys()
.Int8Array.prototype.lastIndexOf()
Array.prototype.lastIndexOf()
.Int8Array.prototype.map()
Array.prototype.map()
.Int8Array.prototype.move()
未实现Int8Array.prototype.copyWithin()
早期的不标准定义。Int8Array.prototype.reduce()
Array.prototype.reduce()
.Int8Array.prototype.reduceRight()
Array.prototype.reduceRight()
.Int8Array.prototype.reverse()
Array.prototype.reverse()
.Int8Array.prototype.set()
Int8Array.prototype.slice()
Array.prototype.slice()
.Int8Array.prototype.some()
Array.prototype.some()
.Int8Array.prototype.sort()
Array.prototype.sort()
.Int8Array.prototype.subarray()
Int8Array.prototype.values()
Array.prototype.values()
.Int8Array.prototype.toLocaleString()
Array.prototype.toLocaleString()
.Int8Array.prototype.toString()
Array.prototype.toString()
.Int8Array.prototype[@@iterator]()
// 以长度参数构造对象
var int8 = new Int8Array(2);
int8[0] = 42;
console.log(int8[0]); // 42
console.log(int8.length); // 2
console.log(int8.BYTES_PER_ELEMENT); // 1
// 以数组构造对象
var arr = new Int8Array([21,31]);
console.log(arr[1]); // 31
// 从另一数组构造对象
var x = new Int8Array([21, 31]);
var y = new Int8Array(x);
console.log(y[0]); // 21
// 从ArrayBuffer构造对象
var buffer = new ArrayBuffer(8);
var z = new Int8Array(buffer, 1, 4);
规范 | 状态 | 评论 |
---|---|---|
Typed Array Specification | Obsolete | 已被 ECMAScript 6取代。 |
ECMAScript 2015 (6th Edition, ECMA-262) TypedArray constructors |
Standard | ECMA 标准中构造对象时 new 关键字为必需。 |
ECMAScript Latest Draft (ECMA-262) TypedArray constructors |
Draft |
功能 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 7.0 | 4.0 (2) | 10 | 11.6 | 5.1 |
new is required |
? | 44 (44) | ? | ? | ? |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 4.0 | (Yes) | 4.0 (2) | 10 | 11.6 | 4.2 |
new is required |
? | ? | 44.0 (44) | ? | ? | ? |
自 ECMAScript 2015 (ES6)施行, Int8Array
需要使用new
构造. 从当前版本开始,不加new而便调用Int8Array
构造器方法, 将报出 TypeError
错误.
var dv = Int8Array([1, 2, 3]);
// TypeError: calling a builtin Int8Array constructor
// without new is forbidden
var dv = new Int8Array([1, 2, 3]);