Created
September 27, 2016 06:09
-
-
Save amirasaran/0cc70255c71e7f125ee427d7a1f84bc1 to your computer and use it in GitHub Desktop.
Java Script replace all in string (str_replace)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.replaceAll = function(search, replacement) { | |
var target = this; | |
return target.replace(new RegExp(search, 'g'), replacement); | |
}; | |
/** | |
* Example | |
*/ | |
var string = "Hello world! Hello my friends"; | |
string = string.replaceAll('Hello', 'Hi'); | |
console.log(string); //out put is "Hi world! Hi my friends" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good job 👍