How to increment letters in TypeScript

1 Answer

0 votes
function nextChar(char : string) : string {
  	return String.fromCharCode(char.charCodeAt(0) + 1);
}

console.log(nextChar('a')); 
console.log(nextChar('b')); 
console.log(nextChar('c')); 

console.log(nextChar('A')); 
console.log(nextChar('B')); 
console.log(nextChar('C'));  
  
  
  
  
/*
run:
  
"b" 
"c" 
"d" 
"B" 
"C" 
"D" 
  
*/

 



answered May 3, 2022 by avibootz

Related questions

1 answer 187 views
1 answer 231 views
1 answer 181 views
1 answer 227 views
1 answer 269 views
4 answers 346 views
...