In JavaScript, how to get a string representation of an ASCII value, e.g. how to turn 65 into A?
Asked
Active
Viewed 9.4k times
68
Michał Perłakowski
- 80,501
- 25
- 149
- 167
Sakthivel
- 1,833
- 12
- 28
- 41
-
2you 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 Answers
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
-
See also [MDN docs](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode). – Michał Perłakowski Jan 02 '16 at 18:56
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