Typed Arrays

Typed Arrays (JavaScript)


You can use typed arrays to handle binary data from sources such as network protocols, binary file formats, and raw graphics buffers. Typed arrays can also be used to manage in-memory binary data with well-known byte layouts.

The following code shows how to use an ArrayBuffer Object as the response of an XMLHttpRequest. You can manipulate the bytes in the response by using the different methods of the DataView Object, or by copying the bytes into the appropriate typed array.


For more information about using different response types with an XmlHttpRequest, see , , and .8d7738d1-4bfd-4cf1-8015-174def089556BE09137C-6546-441B-B953-DCBF72B77069C0006BBD-17F9-4C6A-AF81-2ACAF109111D

<div id="xhrDiv"></div>
var name = "http://www.microsoft.com";
var xhrDiv = document.getElementById("xhrDiv");

var req = new XMLHttpRequest();
req.open("GET", name, true);
req.responseType = "arraybuffer";
req.onreadystatechange = function () {
if (req.readyState == req.DONE) {
    var arrayResponse = req.response;
    var dataView = new DataView(arrayResponse);
    var ints = new Uint32Array(dataView.byteLength / 4);

    xhrDiv.style.backgroundColor = "#00FF00";
    xhrDiv.innerText = "Array is " + ints.length + "uints long";

An ArrayBuffer Object represents a buffer of raw data that is used to store data for the different typed arrays. You cannot read from or write to an ArrayBuffer, but you can pass it to a typed array or DataView Object to interpret the raw buffer. You can use an ArrayBuffer to store any kind of data (or mixed types of data).

You can use a DataView Object to read and write the different kinds of binary data to any location in the ArrayBuffer.

The typed array types represent views of an ArrayBuffer Object that can be indexed and manipulated. All array types are of fixed length.


Size (in bytes)


Int8Array Object


Eight-bit two's complement signed integer

Uint8Array Object


Eight-bit unsigned integer

Int16Array Object


Sixteen-bit two's complement signed integer

Uint16Array Object


Sixteen-bit unsigned integer

Int32Array Object


Thirty-two-bit two's complement signed integer

Uint32Array Object


Thirty-two-bit unsigned integer

Float32Array Object


Thirty-two-bit IEEE floating point

Float64Array Object


Sixty-four-bit IEEE floating point

© 2015 Microsoft