Summary
The Int16Array typed array represents an array of twos-complement 16-bit signed integers in the platform byte order. If control over byte order is needed, use DataView instead. The contents are initialized to 0. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation).
Syntax
Int16Array(length); Int16Array(typedArray); Int16Array(object); Int16Array(buffer [, byteOffset [, length]]);
For more information about the constructor syntax and the parameters, see TypedArray.
Properties
-
Int16Array.BYTES_PER_ELEMENT -
Returns a number value of the element size.
2in the case of anInt16Array. - Int16Array.length
- Length property whose value is 3.
-
Int16Array.name -
Returns the string value of the constructor name. In the case of the
Int16Arraytype: "Int16Array". -
Int16Array.prototype - Prototype for the TypedArray objects.
Methods
- Int16Array.from()
-
See
Array.from(). Not implemented, see bug 896608. - Int16Array.of()
-
See
Array.of(). Not implemented, see bug 896608.
Int16Array prototype
All Int16Array objects inherit from %TypedArray%.prototype.
Properties
-
Int16Array.prototype.constructor -
Returns the function that created an instance's prototype. This is the
Int16Arrayconstructor by default. -
Int16Array.prototype.bufferRead only -
Returns the
ArrayBufferreferenced by theInt16ArrayFixed at construction time and thus read only. -
Int16Array.prototype.byteLengthRead only -
Returns the length (in bytes) of the
Int16Arrayfrom the start of itsArrayBuffer. Fixed at construction time and thus read only. -
Int16Array.prototype.byteOffsetRead only -
Returns the offset (in bytes) of the
Int16Arrayfrom the start of itsArrayBuffer. Fixed at construction time and thus read only. -
Int16Array.prototype.lengthRead only -
Returns the number of elements hold in the
Int16Array. Fixed at construction time and thus read only.
Methods
-
Int16Array.prototype.copyWithin() -
See
Array.prototype.copyWithin(). -
Int16Array.prototype.move()Unimplemented -
Former non-standard version of
Int16Array.prototype.copyWithin(). -
Int16Array.prototype.set() -
Stores multiple values in the
Int16Array, reading input values from a specified array. -
Int16Array.prototype.subarray() -
Returns a new
Int16Arrayfrom the given start and end element index.
Examples
// From a length var int16 = new Int16Array(2); int16[0] = 42; console.log(int16[0]); // 42 console.log(int16.length); // 2 console.log(int16.BYTES_PER_ELEMENT); // 2 // From an array var arr = new Int16Array([21,31]); console.log(arr[1]); // 31 // From another TypedArray var x = new Int16Array([21, 31]); var y = new Int16Array(x); console.log(y[0]); // 21 // From an ArrayBuffer var buffer = new ArrayBuffer(8); var z = Int16Array(buffer, 0, 4);
Specifications
| Specification | Status | Comment |
|---|---|---|
| Typed Array Specification | Obsolete | Superseded by ECMAScript 6. |
| ECMAScript 6 (ECMA-262) The definition of 'TypedArray constructors' in that specification. |
Draft | Initial definition in an ECMA standard. |
Browser compatibility
Help improve compatibility tables by filling out this 11 question survey.
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 7.0 | 4.0 (2) | 10 | 11.6 | 5.1 |
| 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 |