How to get the Nth character in a string with JavaScript

1 Answer

0 votes
const str = 'javascript c++ c php';

console.log(str.charAt(0)); 
console.log(str.charAt(1)); 

console.log(str.charAt(str.length - 1)); 
console.log(str.charAt(str.length - 2)); 
  
  
  
  
/*
run:

"j"
"a"
"p"
"h"
  
*/

 



answered May 15, 2022 by avibootz

Related questions

...