There is no direct way to use the built-in function replace, but you can always create a new function for it:
String.prototype.betterReplace = function(search, replace, from) {
if (this.length > from) {
return this.slice(0, from) + this.slice(from).replace(search, replace);
}
return this;
}
var str = "abcedfabcdef"
console.log(str.betterReplace("a","z","2"))
Run codeHide resultDekel source
share