OneCompiler

[Javascript] How can I remove the first and the last character of a string?

I want to remove the first and last characters from a given string. How to do that in Javascript?

1 Answer

4 years ago by

slice() method can be used to remove first and last character of the string. Check out the below example for the usage

let str = '*Hello World*';
console.log(str.slice(1,str.length-1));

Run here https://onecompiler.com/javascript/3xnrkuf3n

4 years ago by Meera