To replace occurrences of a string in JavaScript, use the replace() method −
<html> <body> <script> var str1 = 'John loves studying. He loves Football too!'; var str2 = str1.replace(/loves/g, "likes"); document.write(str2); </script> </body> </html>
To replace occurrences of a string in JavaScript, use the replace() method −
<html> <body> <script> var str1 = 'John loves studying. He loves Football too!'; var str2 = str1.replace(/loves/g, "likes"); document.write(str2); </script> </body> </html>