69

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

Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
Sakthivel
  • 1,883
  • 12
  • 29
  • 41
  • 2
    you may mark his answer as correct. There's a little check right below the downvote arrow. – kongaraju Sep 27 '12 at 10:04
  • See also: [How to convert from Hex to ASCII in javascript?][1] [1]: http://stackoverflow.com/questions/3745666/how-to-convert-from-hex-to-ascii-in-javascript – BearCode Jun 12 '13 at 04:07

4 Answers4

122

The fromCharCode method converts ASCII to a string:

<script type="text/javascript">
document.write(String.fromCharCode(65,66,67)); // ABC
</script>
starball
  • 20,030
  • 7
  • 43
  • 238
Canavar
  • 47,715
  • 17
  • 91
  • 122
10

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

Usage:

var myAString = String.fromCharCode(65)

UpTheCreek
  • 31,444
  • 34
  • 152
  • 221
3

The method you're looking for is String.fromCharCode (http://www.w3schools.com/jsref/jsref_fromCharCode.asp).

jonnii
  • 28,019
  • 8
  • 80
  • 108
-1

charCodeAt() method can be used to get the ASCII value.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
ak000ay
  • 18
  • 4