Sometimes, we want to convert byte array to string in JavaScript.
In this article, we’ll look at how to convert byte array to string in JavaScript.
How to convert byte array to string in JavaScript?
To convert byte array to string in JavaScript, we can use the String.fromCharCode
method.
For instance, we write
const s = String.fromCharCode(...[102, 111, 111]);
to call String.fromCharCode
with a number array with the character codes spread as arguments of it.
It returns string s
with the characters that correspond to the character codes.
Conclusion
To convert byte array to string in JavaScript, we can use the String.fromCharCode
method.