Jezyk Danzowki Jezyk Danzowki - 1 year ago 158
TypeScript Question

Angular2 Typescript how to increment alphabet index

I know how to do this in Php, as it is a simple, but i am struggling to get a version working.

for ($i = 'A'; $i < 'Z'; $i++) {
$k = $i;
echo "$i->$k, ";

Basically i want to pass a letter into a function and get the next letter in the alphabet. Is there any easy ways or directions that i could be pointed in.

Answer Source

This should do what you want:

getNextLetter(char: String): String {
    code: Number = char.charCodeAt(0);
    return String.fromCharCode(code);