Utilizor
Contact Us

replace, replaceAll

Replacing string content.

Replacing String Content

The replace() method replaces a specified value with another value in a string.

let newText = text.replace("Microsoft", "W3Schools");

By default, the replace() method replaces only the first match.

The replaceAll() method allows you to specify a regular expression instead of a string to be replaced.

Example

let text = "Visit Microsoft!";
let result = text.replace("Microsoft", "W3Schools");