'how to convert string to bytes in javascript

I have a string value like 1,2,3 and i need convert to byte value like [1,2,3]?

how to bind javascript byte to C# Byte[] array

const file = e.files[0];
var reader = new FileReader();
reader.readAsArrayBuffer(file.rawFile);
reader.onload = function () {
     var strBytes = new Uint8Array(reader.result).join();
     var byte=???;
}

thanks



Solution 1:[1]

When creating a Uint8Array, the data is stored as bytes, which is exactly what you are looking for here.

What you've done when using .join() is to create them as strings.

Just remove the .join and you will have an array of bytes:

var strBytes = new Uint8Array(reader.result);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Koby Douek