How to get the first and last characters of a string in Node.js

2 Answers

0 votes
const str = "node.js";
 
const first = str.charAt(0);
console.log(first); 
 
const last = str.charAt(str.length - 1);
console.log(last); 
 
  
  
 
  
/*
run:
 
n
s
 
*/

 



answered Feb 10, 2022 by avibootz
0 votes
const str = "node.js";
 
const first = str[0];
console.log(first); 
 
const last = str[str.length - 1];
console.log(last); 
 
  
  
 
  
/*
run:
 
n
s
 
*/

 



answered Feb 10, 2022 by avibootz

Related questions

1 answer 126 views
1 answer 146 views
1 answer 180 views
1 answer 97 views
...