String.classPrototype.replace

Instance of

Function

Parameters

pattern /*String*/, replacement /*String*/, [inPlace = false /*Boolean*/]

Return value

/*Number*/

Description

The replace method returns a new string with the first match of a pattern replaced by a replacement. If inPlace is true, the original string is modified

Example

let sentence = "The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?";
console.write(sentence.replace("dog", "monkey"));

Expected output

The quick brown fox jumps over the lazy monkey. If the dog reacted, was it really lazy?

This page has text and code adapted from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
Prose content on this page is available under (CC-BY-SA 2.5).
Code examples on this page and snippets are in the public domain (CC0).