Replace-1

 

JavaScript replace() function replace the string provided with new value. See the code snippet:

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <p id="sample">Visit Google!</p> <button onclick="newString()">Replace string</button> <script> function newString() { var str = document.getElementById("sample").innerHTML; var result = str.replace("Google", "LearnKode"); document.getElementById("sample").innerHTML = result; } </script> </body> </html>
Output