Example of a function in JS that converts characters to ASCII values

  • 2020-03-29 23:56:53
  • OfStack

Characters to ASCII: charCodeAt();
ASCII to character: use fromCharCode();

Let's do a little example


<script>
str="A";
code = str.charCodeAt(); 
str2 = String.fromCharCode(code);
str3 = String.fromCharCode(0x60+26);
document.write(code+'<br />');
document.write(str2+'<br />');
document.write(str3);
</script>

Output:

65
a.
z


Related articles: