Answers for "javascript replace last occurrence of a letter"

1

javascript replace last character

var str1 = "Notion,Data,Identity,".replace(/.$/,".")
Posted by: Guest on April-28-2021
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 "javascript replace last occurrence of a letter"

Code answers related to "Javascript"

Browse Popular Code Answers by Language