How to convert letters to numbers with Javascript? -


how convert letter corresponding number in javascript?

for example:

a = 0 b = 1 c = 2 d = 3 

i found question on converting numbers letters beyond 26 character alphabet, asking opposite.

is there way without huge array?

you can codepoint* index in string using string.prototype.charcodeat. if string single character, you’ll want index 0, , code a 97 (easily obtained javascript 'a'.charcodeat(0)), can do:

s.charcodeat(0) - 97 

and in case wanted go other way around, string.fromcharcode takes unicode codepoints* , returns string.

string.fromcharcode(97 + n) 

* not quite


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -