How to decrement letters in JavaScript

1 Answer

0 votes
function prevChar(char) {
  	return String.fromCharCode(char.charCodeAt(0) - 1);
}

console.log(prevChar('a')); 
console.log(prevChar('b')); 

console.log(prevChar('A')); 
console.log(prevChar('B')); 
  
  
  
  
  
/*
run:
  
"`"
"a"
"@"
"A"
  
*/

 



answered May 3, 2022 by avibootz

Related questions

1 answer 86 views
86 views asked May 3, 2022 by avibootz
1 answer 107 views
2 answers 172 views
1 answer 149 views
2 answers 138 views
138 views asked Jul 23, 2022 by avibootz
1 answer 149 views
1 answer 164 views
...