[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Int8Array [Back]  [Original]

Int8Array - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Int8Array

20157

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.length

3 Int8Array.prototype.length

Int8Array.prototype

TypedArray

Int8Array.from()

int8Array Array.from()

Int8Array.of()

Int8Array Array.of()

TypedArray

Int8Array.prototype.constructor

Int8Array

Int8Array.prototype.buffer

Returns the ArrayBuffer referenced by the Int8Array Fixed at construction time and thus read only.

Int8Array.prototype.byteLength

Returns the length (in bytes) of the Int8Array from the start of its ArrayBuffer. Fixed at construction time and thus read only.

Int8Array.prototype.byteOffset

Returns the offset (in bytes) of the Int8Array from the start of its ArrayBuffer. Fixed at construction time and thus read only.

Int8Array.prototype.length

Returns the number of elements hold in the Int8Array. Fixed at construction time and thus read only.

TypedArray

js
// 
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);

ECMAScript 2027 LanguageSpecification
# sec-typedarray-objects

ECMAScript 2015 (ES6) Int8Array new new Int8Array TypeError

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


Web Proxy Viewer  |  New URL  |  Original Page