js replace last character code example
Example 1: js remove last character from string
let str = "Hello Worlds";
str = str.slice(0, -1);
Example 2: 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);
Example 3: javascript replace last character
var str1 = "Notion,Data,Identity,".replace(/.$/,".")
Example 4: js remove last character from string
let str = "12345.00";
str = str.substring(0, str.length - 1);
console.log(str);