Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a string or char from an ASCII value in JavaScript?

In JavaScript, how to get a string representation of an ASCII value, e.g. how to turn 65 into A?

like image 908
Sakthivel Avatar asked Mar 02 '09 11:03

Sakthivel


People also ask

How do you convert ASCII to string?

To convert ASCII to string, use the toString() method. Using this method will return the associated character.

What is fromCharCode in JavaScript?

fromCharCode() method converts Unicode values to characters. The String. fromCharCode() is a static method of the String object. The syntax is always String.


2 Answers

The fromCharCode method converts ASCII to a string:

<script type="text/javascript"> document.write(String.fromCharCode(65,66,67)); // ABC </script> 

Hope this helps!

like image 53
Canavar Avatar answered Oct 11 '22 20:10

Canavar


A reference for those of us that don't like w3schools ;)

Usage:

var myAString = String.fromCharCode(65)

like image 20
UpTheCreek Avatar answered Oct 11 '22 18:10

UpTheCreek