Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirasaran/0cc70255c71e7f125ee427d7a1f84bc1 to your computer and use it in GitHub Desktop.
Save amirasaran/0cc70255c71e7f125ee427d7a1f84bc1 to your computer and use it in GitHub Desktop.
Java Script replace all in string (str_replace)
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"
@mhipo1364
Copy link

Good job 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment