Convert number to alphabet letter

xpedobearx picture xpedobearx · Mar 21, 2016 · Viewed 14.6k times · Source

I want to convert a number to its corresponding alphabet letter. For example:

1 = A
2 = B
3 = C

Can this be done in javascript without manually creating the array? In php there is a range() function that creates the array automatically. Anything similar in javascript?

Answer

Nina Scholz picture Nina Scholz · Mar 21, 2016

Yes, with Number#toString(36) and an adjustment.

var value = 10;

document.write((value + 9).toString(36).toUpperCase());