Standard built-ins
String.prototype.replaceAll()
Replaces each nonoverlapping literal match or delegates to a global regex. An ordinary regex without g throws TypeError.
Formal Syntax & Structure
javascript syntaxjavascript
text.replaceAll(searchValue, replaceValue)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| searchValue | String | RegExp | Literal or pattern to match. |
| replaceValue | String | Function | Substitution string or callback returning replacement text. |
Return Value
String
Updated text; original unchanged.
Working Example
Example Snippetjavascript
console.log("aaa".replaceAll("a","b"));