replaceAll()
ES2021+Returns a new string with all matches of a pattern replaced by a replacement.
Syntax
string.replaceAll(searchValue, replaceValue)Parameters
searchValue string | RegExp The value to search for (must be global if RegExp)
replaceValue string | Function The replacement string or function
Return Value
string
A new string with all replacements made
Examples
JavaScript
const str = 'Hello World World';
console.log(str.replaceAll('World', 'JS')); Output:
// 'Hello JS JS'