How to get the last character of a string in Node.js

2 Answers

0 votes
const s = "node.js";
  
const lastCharacter = s.substr(s.length - 1);
  
console.log(lastCharacter);
  
  
  
    
      
/*
run:
      
s
      
*/

 



answered Jun 20, 2022 by avibootz
0 votes
const s = "node.js";
  
const lastCharacter = s.slice(-1);
  
console.log(lastCharacter);
  
  
  
    
      
/*
run:
      
s
      
*/

 



answered Jun 20, 2022 by avibootz

Related questions

...