JavaScript chop/slice/trim off last character in string code example

Example 1: JavaScript chop/slice/trim off last character in string

let str = "12345.00";
str = str.substring(0, str.length - 1);
console.log(str);

Example 2: JavaScript chop/slice/trim off last character in string

//You can use the substring function:

let str = "12345.00";
str = str.substring(0, str.length - 1);
console.log(str);



//This is the accepted answer, but as per the conversations below, the slice syntax is much clearer:

let str = "12345.00";
str = str.slice(0, -1); 
console.log(str);