68

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

Michał Perłakowski
  • 80,501
  • 25
  • 149
  • 167
Sakthivel
  • 1,833
  • 12
  • 28
  • 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

3 Answers3

122

The fromCharCode method converts ASCII to a string:

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

Hope this helps!

Clemens Himmer
  • 1,289
  • 2
  • 13
  • 26
Canavar
  • 47,036
  • 17
  • 87
  • 121
10

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

Usage:

var myAString = String.fromCharCode(65)

UpTheCreek
  • 30,123
  • 33
  • 148
  • 220
3

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

jonnii
  • 27,675
  • 6
  • 78
  • 108