Represents a raw buffer of binary data, which is used to store data for the different typed arrays. ArrayBuffers cannot be read from or written to directly, but can be passed to a typed array or DataView Object to interpret the raw buffer as needed.
For more information about typed arrays, see Typed Arrays (JavaScript).
arrayBuffer = new ArrayBuffer(length);
The following example shows how to use an ArrayBuffer object to process the binary data acquired from an XmlHttpRequest. You can use a DataView Object to get the individual values.
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 Int32Array(buffer.byteLength / 4); for (var i = 0; i < ints.length; i++) { ints[i] = dataview.getInt32(i * 4); } alert(ints[10]); } }
For more information about using XmlHttpRequest, see XMLHttpRequest enhancements.
Supported in the Internet Explorer 10 standards document mode. Also supported in Windows Store apps. 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.