Replace all in javascript

String Replace Using JavaScript

// Replace All
String.prototype.replaceAll = function (s, r) {
    return this.split(s).join(r)
}
// Print
var print = function (val) {
    document.body.innerHTML = document.body.innerHTML + "<br />" + val
}
// EXAMPLE RETURNS
print("Replace all commas in a string".replaceAll("commas", ","))
print("javascript find and replace".replaceAll("find", "search"))
print("string replace in javascript".toLowerCase().replaceAll("i", "I"))
print("String Replace CaSe sensitive JavaScript".replaceAll("s", "ins"))
DEMO
Replace all in javascript Replace all in javascript Reviewed by Bhaumik Patel on 7:43 PM Rating: 5