Class Int16Array

<!-- prettier-ignore-start -->

An optimized array to store 16-bit signed integer numbers. Elements of this array are stored in an ArrayBuffer object.

API Version: note: Available from version 21.2.

Constant Summary

Constant Description
BYTES_PER_ELEMENT: Number = 2 Number value of the element size.

Property Summary

Property Description
buffer: ArrayBuffer The array buffer referenced by this typed array.
byteLength: Number The number of bytes in the array buffer used by this typed array.
byteOffset: Number The start offset for this typed array within the array buffer.
length: Number The number of elements.

Constructor Summary

Constructor Description
Int16Array() Creates an empty array.
Int16Array(Number) Creates an array with the given element count.
Int16Array(Object) Creates an array as a copy of the passed typed array.
Int16Array(Array) Creates an array as a copy of the passed array.
Int16Array(ArrayBuffer, Number, Number) Creates a typed array as a view on the given ArrayBuffer.

Method Summary

Method Description
get(Number) Returns the value at the specified index.
set(Object, Number) Copies all values from the source array into this typed array.
subarray(Number, Number) Returns a new array object based on the same ArrayBuffer store.

Methods inherited from class Object

assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values

Constant Details

BYTES_PER_ELEMENT

  • BYTES_PER_ELEMENT: Number = 2
    • : Number value of the element size.

Property Details

buffer

  • buffer: ArrayBuffer
    • : The array buffer referenced by this typed array.

byteLength

  • byteLength: Number
    • : The number of bytes in the array buffer used by this typed array.

byteOffset

  • byteOffset: Number
    • : The start offset for this typed array within the array buffer.

length

  • length: Number
    • : The number of elements.

Constructor Details

Int16Array()

  • Int16Array()
    • : Creates an empty array.

Int16Array(Number)

  • Int16Array(length: Number)
    • : Creates an array with the given element count.

      Parameters:

      • length - The number of elements.

Int16Array(Object)

  • Int16Array(typedArray: Object)
    • : Creates an array as a copy of the passed typed array.

      Parameters:

      • typedArray - The source typed array.

Int16Array(Array)

  • Int16Array(array: Array)
    • : Creates an array as a copy of the passed array.

      Parameters:

      • array - The source array.

Int16Array(ArrayBuffer, Number, Number)

  • Int16Array(buffer: ArrayBuffer, byteOffset: Number, length: Number)
    • : Creates a typed array as a view on the given ArrayBuffer.

      Parameters:

      • buffer - The array buffer storage object.
      • byteOffset - Optional. The offset within the array buffer in bytes.
      • length - Optional. The number of elements for the target typed array. The passed array buffer must be large enough to store the number of elements specified.

Method Details

get(Number)

  • get(index: Number): Number
    • : Returns the value at the specified index.

      Note: This is not ECMAScript standard. Use array element access syntax for single value access.

      Parameters:

      • index - The index to use.

      Returns:

      • The value at the specified index.

set(Object, Number)

  • set(values: Object, offset: Number): void
    • : Copies all values from the source array into this typed array.

      Parameters:

      • values - The source values. Can be an array or a typed array.
      • offset - Optional. Target offset.

subarray(Number, Number)

  • subarray(begin: Number, end: Number): Int16Array
    • : Returns a new array object based on the same ArrayBuffer store.

      Parameters:

      • begin - Optional. The first included element.
      • end - Optional. The index of the end. This element is not included.

      Returns:

      • The new array object.

<!-- prettier-ignore-end -->