replace() method replaces the first occurrence of a substring in a string.
syntax ↴
replace(searchValue, replaceValue) ↴
searchValue Can be a string or an object with a Symbol.replace method - the typical example being a regular expression.
Any value that doesn't have the Symbol.replace method will be coerced to a string.
replaceValue Can be a string or a function ↴
If it's a string, it will replace the first occurrence of searchValue with replaceValue string.
If it's a function, it will be invoked for every match and its return value is used as the replacement text.
replace() method searches a string for a value or a regular expression.
replace() method returns a new string with the value(s) replaced.
replace() method does not change the original string.
Only the first occurrence will be replaced.
To replace all instances, use a regular expression with the global g flag set, or use the replaceAll() method.
If the searchValue input is left empty, the replaceValue character(s) are prepended to the start of the string.
If the replaceValue input is left empty, the searchValue character(s) are removed from the string.
myString.replace(searchValue, replaceValue)