Answers for "JavaScript chop/slice/trim off last character in string"

3

JavaScript chop/slice/trim off last character in string

let str = "12345.00";
str = str.substring(0, str.length - 1);
console.log(str);
Posted by: Guest on December-13-2019
0

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);
Posted by: Guest on December-30-2020

Code answers related to "JavaScript chop/slice/trim off last character in string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language