The strReplaceAll() method returns a new string with all matches of a pattern replaced by a replacement.
The string value to search and replace within.
The value to search for. Can be a string or a global regular expression.
The replacement string or replacer function.
A new string with every occurrence of searchValue replaced.
0.14.0
TypeError if searchValue is a regular expression without the global flag.
strReplaceAll("a-b-a", "a", "x"); // "x-b-x"strReplaceAll("abc123abc", /abc/g, "X"); // "X123X"strReplaceAll("abca", "a", (value, index) => value.toUpperCase() + index);// "A0bcA3" Copy
strReplaceAll("a-b-a", "a", "x"); // "x-b-x"strReplaceAll("abc123abc", /abc/g, "X"); // "X123X"strReplaceAll("abca", "a", (value, index) => value.toUpperCase() + index);// "A0bcA3"
The strReplaceAll() method returns a new string with all matches of a pattern replaced by a replacement.