Your Search Results

    Uint16Array Redirect 2

    API

    The Uint16Array type represents an array of unsigned 16-bit integers in the platform byte order. If control over byte order is needed, use DataView instead.

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

    Constructors

    Note: In these methods, TypedArray represents any of the typed array object types.
    Uint16Array Uint16Array(unsigned long length);
    Uint16Array Uint16Array(TypedArray array);
    Uint16Array Uint16Array(sequence<type> array);
    Uint16Array Uint16Array(ArrayBuffer buffer, optional unsigned long byteOffset, optional unsigned long length);

    Method overview

    Note: In these methods, TypedArray represents any of the typed array object types.
    void set(TypedArray array, optional unsigned long offset);
    void set(type[] array, optional unsigned long offset);
    Uint16Array subarray(long begin, optional long end);

    Attributes

    Attribute Type Description
    buffer ArrayBuffer The ArrayBuffer object used to contain the TypedArray datas. Read only.
    byteOffset unsigned long The index at wich starts the TypedArray in it underlying ArrayBuffer. Read only.
    length unsigned long The number of entries in the array. Read only.

    Constants

    Element size

    Constant Value Description
    BYTES_PER_ELEMENT 2 The size, in bytes, of each array element.

    Constructor

    Returns a new Uint16Array object.

    Uint16Array Uint16Array(
      unsigned long length
    );
    
    Uint16Array Uint16Array(
      TypedArray array
    );
    
    Uint16Array Uint16Array(
      sequence<type> array
    );
    
    Uint16Array Uint16Array(
      ArrayBuffer buffer,
      optional unsigned long byteOffset,
      optional unsigned long length
    );
    
    Parameters
    length
    The number of elements in the byte array. If unspecified, length of the array view will match the buffer's length.
    array
    An object of any of the typed array types (such as Int32Array), or a sequence of objects of a particular type, to copy into a new ArrayBuffer. Each value in the source array is converted to a 16-bit unsigned integer before being copied into the new array.
    buffer
    An existing ArrayBuffer to use as the storage for the new Uint16Array object.
    byteOffset
    The offset, in bytes, to the first byte in the specified buffer for the new view to reference. If not specified, the Uint16Array's view of the buffer will start with the first byte.
    Return value

    A new Uint16Array object representing the specified data buffer.

    Notes

    The first form of the constructor, accepting only a length, creates a new ArrayBuffer object that can hold the specified number of unsigned 16-bit integers, then creates and returns a typed array view referring to that new buffer. The length must be specified in this case.

    The second form creates a new ArrayBuffer object that is a duplicate of the specified array, except with each element in the new array converted to a 16-bit unsigned integer.

    The third form of the constructor likewise creates a new ArrayBuffer object that is a duplicate of the specified JavaScript array, with each element in the new array converted to a 16-bit unsigned integer.

    The final form of the constructor creates a new Uint16Array object, using the specified ArrayBuffer as its storage. This lets you access the existing buffer in a different format. If specified, the byteOffset and length parameters let you create the new view to only a portion of the buffer.

    Exceptions thrown
    INDEX_SIZE_ERR
    The specified byteOffset isn't a multiple of the element size, or the byteOffset and length result in the specified view extending past the end of the buffer.

    Methods

    set()

    Sets multiple values in the typed array, reading input values from a specified array.

    void set(
      TypedArray array,
      optional unsigned long offset
    );
    
    void set(
      type[] array,
      optional unsigned long offset
    );
    
    Parameters
    array
    An array from which to copy values. All values from the source array are copied into the target array, unless the length of the source array plus the offset exceeds the length of the target array, in which case an exception is thrown. If the source array is a typed array, the two arrays may share the same underlying ArrayBuffer; the browser will intelligently copy the source range of the buffer to the destination range.
    offset Optional
    The offset into the target array at which to begin writing values from the source array. If you omit this value, 0 is assumed (that is, the source array will overwrite values in the target array starting at index 0).

    subarray()

    Returns a new Uint16Array view on the ArrayBuffer store for this Uint16Array object.

    Uint16Array subarray(
      long begin,
      optional long end
    );
    
    Parameters
    begin
    The offset of the first element in the array to be referenced by the new Uint16Array object.
    end Optional
    The offset of the element one-past the last element to be referenced by the new Uint16Array object; if not specified, all elements from the one specified by begin to the end of the array are included in the new view.
    Notes

    The range specified by begin and end is clamped to the valid index range for the current array; if the computed length of the new array would be negative, it's clamped to zero. If either begin or end is negative, it refers to an index from the end of the array instead of from the beginning.

    Note: Keep in mind that this is creating a new view on the existing buffer; changes to the new object's contents will impact the original object and vice versa.

    See also

    Document Tags and Contributors

    Contributors to this page: Sheppy
    Last updated by: Sheppy,