I'm sure you will find this helpful: http://jsdo.it/tsmallfield/uint8array.

Click on javascript tab. There will appear the code to convert the Uint8Array in a string. The author shows 2 method:

  • The first is about creating a view.
  • The second offsetting bytes.

EDIT: report the code for completeness

var buffer = new ArrayBuffer( res.length ), // res is this.response in your case
    view   = new Uint8Array( buffer ),
    len    = view.length,
    fromCharCode = String.fromCharCode,
    i, s, str;    

/**
 *  1) 8bitの配列に入れて上位ビットけずる
 */
str = "";

for ( i = len; i--; ) {
  view[i] = res[i].charCodeAt(0);
}

for ( i = 0; i < len; ++i ) {
  str += fromCharCode( view[i] );
}    

/**
 *  2) & 0xff で上位ビットけずる
 */
str = "";

for ( i = 0; i < len; ++i ) {
  str += fromCharCode( res[i].charCodeAt(0) & 0xff );
}
Answer from user278064 on Stack Overflow
🌐
Webdevtutor
webdevtutor.net › blog › javascript-binary-string-to-byte-array
Converting Binary String to Byte Array in JavaScript
Here's a simple function that demonstrates how you can convert a binary string to a byte array: javascript function binaryStringToByteArray(binaryString) { const byteNumbers = new Array(binaryString.length);
Discussions

casting - Converting byte array to string in javascript - Stack Overflow
For example, (5).toString(2) will ... complete binary conversion is in reality 00000101, and that's why you might need to create a leftPad implementation to fill the string byte with leading zeros. But you may not need it at all, like other answers demonstrated. If you run the below code snippet, you'll see the first output being the conversion of the abc string to a byte array and right ... More on stackoverflow.com
🌐 stackoverflow.com
java - Parse binary string as byte in JavaScript - Stack Overflow
What JavaScript code I should write to get the same output as Java? ... Java is interpreting the byte as being a signed two's-complement number, which is negative since the highest bit is 1. Javascript is interpreting it as unsigned, so it's always positive. More on stackoverflow.com
🌐 stackoverflow.com
October 17, 2014
Converting non-unicode binary strings to byte array in Javascript - Stack Overflow
I read a binary file using ajax from a web server. The HTTP response is of contentType: 'application/octet-stream' and contains a binary string that is just a string of bytes (not unicode), for exa... More on stackoverflow.com
🌐 stackoverflow.com
c# - How to convert binary string to bytes[] array? - Stack Overflow
Since Mozilla's btoa and atob aren't compatible with IE, Im using Nick Galbreath's solution that works across the board. In my JS, I have this snippet: reader.onload = function (e) { var base64... More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 2
1

Update: I'm not so sure [default] Ajax is the right tool for the job in this case. Regardless of file size, it is generally a good practice to use streams instead to accommodate future scalability, as your current method loads everything at once.

This article goes over how to create a custom ajax transport that wraps an XmlHttpRequest to load the data into an array buffer rather. You could do this, sequentially push the bytes into your main array, and go from there.

Old: I'm not sure if I properly understood your data representation, but I believe you can just use parseInt() to turn a hex string into decimal:

var data = ['0x00', '0x08', '0x17', '0xA1', '0x01'];
var parsed = [];

for(var i = 0; i < data.length; i++) {
	parsed.push(parseInt(data[i], 16));
}

console.log(parsed);
console.log(parseInt('0xA1', 16))

If this is not what you mean, please comment and I will try to update my answer with a more specific implementation.

2 of 2
1

Following the suggestion from Haus 's answer I found some more solutions to the problem so I will share my findings here.

  1. My preferred solution is to use ArrayBuffer to access raw data. Unfortunately Ajax does not seem to support it as per this article, although there is an option to add support (which I could not get to work), and there is no straightforward way to create an ArrayBuffer out of string. However XMLHttpRequest supports ArrayBuffer as responseType as explained here so I changed my code to the following, which does what I want:

    var xhr = new XMLHttpRequest();
    xhr.open('GET', url);
    xhr.responseType = 'arraybuffer';  
    xhr.onload = function() {
        if (this.status == 200) {
            var byteTab=[]
            var uint8View = new Uint8Array(this.response)
            for (var n = 0; n < uint8View.byteLength; n++) {
                byteTab.push(uint8View[n])
            }
    
        } 
    };
    xhr.send();
    
  2. Another solution is to get to ArrayBuffer via using Blob, which is explained with an example in this answer

  3. Another option is to use Blob in conjunction with FileReader.readAsBinaryString() along the lines of the example here. Using readAsBinaryString() converts the blob to a unicode string which can then be parsed using charCodeAt()

🌐
GitHub
gist.github.com › lihnux › 2aa4a6f5a9170974f6aa
Javascript Convert String to Byte Array · GitHub
Array.from("1111222223333444445556", , (x) => x.charCodeAt(0)) ... function unpack(str) { var bytes = []; for(var i = 0; i < str.length; i++) { var char = str.charCodeAt(i); bytes.push(char >>> 8); bytes.push(char & 0xFF); } return bytes; } this is the correct way to extract the bytes a JavaScript string is made of
🌐
Reddit
reddit.com › r/javascripttips › how to convert string to byte array in javascript?
r/JavaScriptTips on Reddit: How to Convert String to Byte Array in JavaScript?
May 1, 2023 - This object provides a view of an underlying ArrayBuffer object, which represents a fixed-length, contiguous block of memory. To convert a JavaScript string to a byte array, we can use the TextEncoder interface.
Find elsewhere
🌐
Designcise
designcise.com › web › tutorial › how-to-convert-a-javascript-string-to-a-byte-array
How to Convert a JavaScript String to a Byte Array? - Designcise
April 9, 2023 - In JavaScript, you can convert a string to an array of bytes by using the TextEncoder API, for example, in the following way: function toBytesArray(str) { const encoder = new TextEncoder(); return encoder.encode(str); } console.log(toBytesA...
🌐
Bobby Hadz
bobbyhadz.com › blog › convert-string-to-byte-array-in-javascript
How to convert a String to a Byte Array in JavaScript | bobbyhadz
The TextEncoder() constructor creates a TextEncoder object that is used to generate a byte stream with UTF-8 encoding. The last step is to use the TextEncoder.encode() method. The method takes a string as a parameter and returns Uint8Array object. A Uint8Array represents an array of 8-bit unsigned integers.
🌐
Itsourcecode
itsourcecode.com › home › how to convert string to byte array in javascript?
How to Convert String to Byte Array in JavaScript (2026)
July 9, 2026 - We created an instance of TextEncoder, defined our string, used the encode method to convert the string into bytes, and finally logged the byte array to the console. We hope this article has provided you with enough information to understand the JavaScript string to bytes.
🌐
JavaScript in Plain English
javascript.plainenglish.io › javascript-data-encoding-and-decoding-techniques-buffers-byte-arrays-dataview-binary-219d55b535a2
JavaScript Data Encoding and Decoding Techniques: Buffers, Byte arrays, DataView, binary, hexadecimal, and decimals. | by Varun Kukade | JavaScript in Plain English
May 4, 2024 - Whether to put a string/number/object into a byte array is decided mutually by the sender and receiver. Now receiver reads this byte array, checks the request, and puts the response result in a new byte array. Now receiver sends this new byte array to the sender again.
🌐
Sling Academy
slingacademy.com › article › javascript-convert-a-byte-array-to-a-hex-string-and-vice-versa
JavaScript: Convert a byte array to a hex string and vice versa - Sling Academy
March 13, 2023 - This concise and straightforward article shows you how to convert a byte array into a hex string (hexadecimal string) and vice versa in modern JavaScript (ES6 and above). ... A hex string is a string that represents binary data using hexadecimal notation.
🌐
GitHub
gist.github.com › robingenz › 5736ffd3d2f23966eabec721bb03133e
String to byte array converter in JavaScript · GitHub
String to byte array converter in JavaScript · Raw · convertStringToBytes.js · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
GitHub
gist.github.com › taterbase › 2784890
Convert bytes to string Javascript · GitHub
function bin2string(array){ var result = ""; for(var i = 0; i < array.length; ++i){ result+= (String.fromCharCode(array[i])); } return result; } ... These things are not working when I am trying to print other languages.
🌐
CodingTechRoom
codingtechroom.com › question › convert-binary-string-to-byte-array
How to Convert a Binary String to a Byte Array in Programming - CodingTechRoom
# Python example of converting ... `to_bytes()` method. In Java, use a loop to convert each character to byte. In JavaScript, use `TextEncoder` to convert a binary string to a byte array....