Answers for "how to remove the lasr of string in javascript"

11

js remove the last character of a string

const text = 'abcdef'
const editedText = text.slice(0, -1) //'abcde'
Posted by: Guest on August-27-2020
0

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;
Posted by: Guest on April-12-2022

Code answers related to "how to remove the lasr of string in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language