JavaScript USES the replace function to replace a string

  • 2020-05-26 07:48:36
  • OfStack

This example shows how JavaScript replaces strings with the replace function. Share with you for your reference. The details are as follows:

JavaScript replaces the string with the replace function, and the following code replaces MicroSoft in Visit Microsoft with

<!DOCTYPE html>
Click the button to replace "Microsoft" 
with "" in the paragraph below:
<p id="demo">Visit Microsoft!</p>
<button onclick="myFunction()">Try it</button>
function myFunction()
var str=document.getElementById("demo").innerHTML;
var n=str.replace("Microsoft","");

I hope this article is helpful for you to design javascript program.

Related articles: