How to remove first & last characters of a String in Javascript
I receive String with starting and ending double quotes like following "help"
and I want to extract help
from it. How can I do that in Javascript?
1 Answer
4 years ago by VD
Using Javascript's slice
method on Strings, you can remove the first & last characters like following
console.log(foo.slice(1, -1));
Following is a full example
let foo = '"help"';
console.log(foo.slice(1, -1));
Output
help
You can try the code online here https://onecompiler.com/javascript/3vy56hwfq
4 years ago by Karthik Divi