Introduction
In my previous article, you learned about "Prototype and Prototype Inheritance in JavaScript". In this article, I will tell you about one more new feature of JavaScript in Visual Studio 2012, Typed Arrays.
A Typed Array can be used to handle binary data from various sources such as Network Protocols, Binary File Formats, and Raw Graphic Buffers. Typed Arrays can also be used to manage in-memory Binary Data with a well-known Byte Layout.
Step 1
Now I will tell you how to use an Array Buffer Object as the response of an XMLHttpRequest through an example. You can manipulate the bytes in the response using the various methods of the Data View Object, or by copying the bytes into the appropriate Typed Array.
First of all, add a JavaScript page to your Windows or Web Application. This can be done by right-clicking on your application and then "Add" | "New Item...".

Now in the New Item list select the JavaScript Style Sheet.

Step 2
Now in the Style Sheet write the following code:
- ...
- <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";
- }
- }
- req.send();

Join the conversation! Your thoughts help the community grow.