Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Uint8Array Object

A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the requested number of bytes could not be allocated an exception is raised.

uint8Array = new Uint8Array( length );
uint8Array = new Uint8Array( array );
uint8Array = new Uint8Array( buffer, byteOffset, length);

uint8Array

Required. The variable name to which the Uint8Array object is assigned.

length

Specifies the number of elements in the array.

array

The array (or typed array) that is contained in this array. The contents are initialized to the contents of the given array or typed array, with each element converted to the Uint8 type.

buffer

The ArrayBuffer that the Uint8Array represents.

byteOffset

Optional. Specifies the offset in bytes from the start of the buffer at which the Uint8Array should begin.

length

The number of elements in the array.

The following table lists the constants of the Uint8Arrayobject.

Constant

Description

BYTES_PER_ELEMENT Constant

The size in bytes of each element in the array.

The following table lists the constants of the Uint8Arrayobject.

Property

Description

buffer Property

Read-only. Gets the ArrayBuffer that is referenced by this array.

byteLength Property

Read-only. The length of this array from the start of its ArrayBuffer, in bytes, as fixed at construction time.

byteOffset Property

Read-only. The offset of this array from the start of its ArrayBuffer, in bytes, as fixed at construction time.

length Property

The length of the array.

The following table lists the methods of the Uint8Arrayobject.

Method

Description

set Method (Uint8Array)

Sets a value or an array of values.

subarray Method (Uint8Array)

Gets a new Uint8Array view of the ArrayBuffer store for this array.

The following example shows how to use a Uint8Array object to process the binary data acquired from an XmlHttpRequest:

var req = new XMLHttpRequest();
    req.open('GET', "http://www.example.com");
    req.responseType = "arraybuffer";
    req.send();

    req.onreadystatechange = function () {
        if (req.readyState === 4) {
            var buffer = req.response;
            var dataview = new DataView(buffer);
            var ints = new Uint8Array(buffer.byteLength);
            for (var i = 0; i < ints.length; i++) {
                ints[i] = dataview.getUint8(i);
            }
        alert(ints[10]);
        }
    }

Supported in the following document modes: Internet Explorer 10 standards and Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information. Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft