Answers for "js replace the last character of string"

2

js omit last string

"somestring0".slice(0, -1)
// "somestring"
Posted by: Guest on June-05-2020
0

javascript replace last occurrence of a letter

String.prototype.replaceLast = function (search, replace) {
    return this.replace(new RegExp(search+"([^"+search+"]*)$"), replace+"$1");
}

str = "lala";
newStr = str.replaceLast("l", "m");
console.log(newStr);
Posted by: Guest on May-31-2021

Code answers related to "js replace the last character of string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language