Replace-2

 

With the help of JavaScript replace function, It will replace the string like with love.. Here is the syntax

str.replace(/like/g, "love");

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