Standard built-ins

String.prototype.replace()

Try the free JavaScript compiler

Returns replaced text; a literal search changes at most its first match. Global ordinary regexes replace multiple matches. Callback results are inserted without dollar-substitution expansion.

Formal Syntax & Structure

javascript syntaxjavascript
text.replace(searchValue, replaceValue)

Parameters & Attributes

NameTypeDescription
searchValueString | RegExpLiteral or pattern to match.
replaceValueString | FunctionSubstitution string or callback returning replacement text.

Return Value

String

Updated text; original unchanged.

Working Example

Example Snippetjavascript
console.log("aaa".replace("a","b"));
JavaScript Reference