Sometimes, we want to increment letters with JavaScript.
In this article, we’ll look at how to increment letters with JavaScript.
How to increment letters with JavaScript?
To increment letters with JavaScript, we can use the String.fromCharCode method.
For instance, we write
const c = String.fromCharCode("A".charCodeAt() + 1);
to call String.fromCharCode with "A".charCodeAt() + 1 to return 'B'.
We get the character code of 'A' with charCodeAt.
Then we add 1 to it and use the sum as the argument of fromCharCode to get the letter after 'A'.
Conclusion
To increment letters with JavaScript, we can use the String.fromCharCode method.