0

I have to process a JS Uint8ClampedArray. When I print the full array with document.write(data) the result is fine, but when I access to the first item document.write(data[0]) the result is some undefined and wrong numbers.

The array is created like this:

var myArray = new ArrayBuffer(imgData.data.length);
var data = new Uint8ClampedArray(myArray);
data=httpRequest.responseText;

The information comes from a C cgi program which prints binary data this way:

 for(int i = 0; i<len; i++)
    printf("%u", input[i]);
Raúl Gombru
  • 91
  • 1
  • 8
  • 2
    you do realize that setting `data=httpRequest.responseText` overwrites 'data'? Data now isn't a Uint8ClampedArray anymore, but just a string containing the information from your request. – DoXicK Oct 14 '14 at 08:03
  • `data` is not an Array, so you cannot do `data[0]`. (Technically a string *is* sort of an array but certainly a string isn't what you are expecting.) – Derek 朕會功夫 Oct 14 '14 at 08:10
  • Hint: see this answer for the correct way to do this: http://stackoverflow.com/questions/1645847/ajax-binary-response#answer-10646659 – slebetman Oct 14 '14 at 08:53

0 Answers0