What is a replace JavaScript:- Geniusofstudent

  • The replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.
  • If you are replacing a value (and not a regular expression), only the first instance of the value will be replaced. To replace all occurrences of a specified value, use the global(g) modifier.
  • This method does not change the original string.

Code:-


  • <!DOCTYPE html> 
  • <html> 
  •  
  • <head> 
  •  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  • </head> 
  •  
  • <body> 
  •  
  •  <h1>replace()</h1> 
  •  
  •  <input type="button" onclick="strfun();" value="Get Answer"> 
  •  
  •  <script> 
  •   function strfun() 
  •   { 
  •    var str = "Place of Marthandam"; 
  •    alert(str.replace("Marthandam", "Chennai")); 
  •  
  •    alert(str); //Original string will not affect 
  •   } 
  •  </script> 
  •  
  • </body> 
  •  
  • </html>
What is a replace JavaScript:- Geniusofstudent What is a replace JavaScript:- Geniusofstudent Reviewed by Network security on June 30, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.