How to remove the first and last character from a string in JavaScript

2 Answers

0 votes
let s  = 'javascript';

s = s.slice(1,-1);

console.log(s);



/*
run:

avascrip

*/

 



answered May 21, 2021 by avibootz
0 votes
let s  = 'javascript';

s = s.substring(1, s.length - 1);

console.log(s);



/*
run:

avascrip

*/

 



answered May 21, 2021 by avibootz

Related questions

...