How to pass an array into the JavaScript string fromCharCode method?

Sometimes, we want to pass an array into the JavaScript string fromCharCode method.

In this article, we’ll look at how to pass an array into the JavaScript string fromCharCode method.

How to pass an array into the JavaScript string fromCharCode method?

To pass an array into the JavaScript string fromCharCode method, we call String.fromCharCode method with with an array spread as the arguments of it.

For instance, we write:

const array = [72, 69, 76, 76, 79];
const chars = String.fromCharCode(...array)
console.log(chars)

to call String.fromCharCodewith thearray` entries as the arguments.

We unpacked array with the spread operator.

And then we assign the returned result to chars.

As a result, we get that chars is 'HELLO'.

Conclusion

To pass an array into the JavaScript string fromCharCode method, we call String.fromCharCode method with with an array spread as the arguments of it.