1let str = 'Hello';
2
3str = str.slice(1);
4console.log(str);
5
6/*
7 Output: ello
8*/
9
1// Hey buddy, here are different implementation, choose your favourite !!
2
3// best implementation
4const removeChar = (str) => str.slice(1, -1);
5
6// regex
7function removeChar(str) {
8 return str.replace(/^.|.$/g, "");
9}
10
11// without slice
12function removeChar(str) {
13 const array = str.split("");
14 let res = "";
15 for (let i = 1; i < array.length - 1; i++) res += array[i];
16 return res;
17}
18
1let str = 'Hello';
2
3str = str.substring(1);
4console.log(str);
5
6/*
7 Output: ello
8*/
9