DEV Community

San
San

Posted on

How to convert ASCII code to character using JavaScript ?

How to convert ASCII code to character using JavaScript ?

For example, the ordinary number key 1 generates an event with keycode 49 while numberpad key 1 (with Numlock on) generates keycode 97. Used with String.fromCharCode we get the following:

Output:

console.log(String.fromCharCode(65))
console.log(String.fromCharCode(66))
console.log(String.fromCharCode(67))
console.log(String.fromCharCode(89))
console.log(String.fromCharCode(90))
Enter fullscreen mode Exit fullscreen mode

Top comments (0)