replace()
ES3+Returns a new string with some or all matches of a pattern replaced by a replacement.
Syntax
string.replace(searchValue, replaceValue)Parameters
searchValue string | RegExp The value to search for
replaceValue string | Function The replacement string or function
Return Value
string
A new string with replacements made
Examples
JavaScript
const str = 'Hello World';
console.log(str.replace('World', 'JavaScript'));
console.log(str.replace(/o/g, '0')); Output:
// 'Hello JavaScript'
'Hell0 W0rld'