slice() method by using that we can remove the last character from a string.
Here is an example:
let str = 'hello/'; console.log(str.slice(0,str.length-1));
In the above code, we have passed two arguments to the slice() method. so it begins the slicing at index position 0, and extracts before the last character index.
Similarly, we can also use the
substring() method to remove the last character of a given string.
let str = 'hello/'; console.log(str.substring(0,str.length-1));
substring() method also works similar like
slice method but in
substring() method if argument
one index is greater than argument
two index then arguments are swapped.