How to increment letters in Node.js

1 Answer

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

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

console.log(nextChar('A')); 
console.log(nextChar('B')); 
console.log(nextChar('C'));  
console.log(nextChar('D')); 

  
  
  
/*
run:
  
b
c
d
e
B
C
D
E
  
*/

 



answered May 3, 2022 by avibootz

Related questions

1 answer 133 views
1 answer 119 views
1 answer 132 views
1 answer 138 views
1 answer 192 views
...