Reputation: 43
How do I take an ascii code and convert it into its character using JavaScript? I'm in a nested loop and need to label each loop 1A, 2A, 1B, 2B, etc, and I would like to avoid hard coding every character using if statements.
Upvotes: 4
Views: 5391
Reputation: 1217
You can use String.fromCharCode()
String.fromCharCode(ascii_value)
This is plain Javascript by the way. If you want to use hex numbers, convert them to decimal by using parseInt().
parseInt("ff", 16)
For example, this snippet takes the hex number ff and returns the character ÿ:
String.fromCharCode(parseInt("ff", 16))
Upvotes: 11