Replace method in javascript
The JavaScript replace() method searches a string for a specified value, or a regular expression, and returns a new string with replaced value.
Note: This will not change original string.
Syntax:
string.replace(searchvalue,newvalue)
Where,
searchvalue = Required. The value, or regular expression, that will be replaced by the new value
newvalue = Required. The value to replace the searchvalue with
Example:
var str=”This is the JavaScript method!”;
var n=str.replace(“JavaScript”,”JavaScript replace()”);
alert(n); // OUTPUT: This is the JavaScript replace() method!
Live Demo: JavaScript replace Method