Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

remove the last character from a string in JavaScript,


let str = 'Masteringjs.ioF';
str.slice(0,-1); // Masteringjs.io 
str.substring(0, str.length - 1); // Masteringjs.io
str.substr(0, str.length - 1); // Masteringjs.io
str.replace(/.$/, ''); // Masteringjs.io
// For a number, use d$.
let str = 'Masteringjs.io0';
str.replace(/d$/, ''); // Masteringjs.io
// advanced features
let str2 = 'Masteringjs.io0F';
// If the last character is not a number, it will not replace.
str.replace(/d$/, ''); // Masteringjs.io0F;
Source by masteringjs.io #
 
PREVIOUS NEXT
Tagged: #remove #character #string
ADD COMMENT
Topic
Name
7+9 =