You can use the String.prototype.charCodeAt()
method to convert string characters to ASCII numbers. For example, let’s find ASCII code for the first letter of ‘ABC’ string,
1 | "ABC".charCodeAt(0) // returns 65 |
Whereas String.fromCharCode()
method converts numbers to equal ASCII characters.
1 | String.fromCharCode(65,66,67); // returns 'ABC' |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.