JavaScriptStringreplace

Returns a new string with the first match replaced.

Syntax

str.replace(searchFor, replaceWith)

Example

Enter values below to update the example in real time.

const
console
const text = "Hello World World";
console.log(text.replace("World", "JavaScript"));
// "Hello JavaScript World"