Categories
JavaScript Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *