Replace All in a String using JavaScript, jQuery
This below snippet will help to replace a all occurrence of a word in string using the below example. This method is suitable for JavaScript and jQuery.
To replace first occurrence we can use
var main_str="Find Find Replace";
main_str=main_str.replace("Find","Replace");
alert(main_str);//Will display "Replace Find Replace"
To replace all occurrence in a String using the below code
var main_str="Find Find Replace";
main_str=main_str.replace(/Find/g,"Replace");
alert(main_str);//Will display "Replace Replace Replace"
