The replace()
method in JavaScript replaces a specified string with a given string.
The syntax of this method is as follows:
str.replace(oldString, newString);
The replace()
method takes two mandatory string/character parameters. The first string is the one that needs to be replaced. The second string is the one that needs to be placed.
The return value is the updated string with the replaced bits in it.
In the code below, the replace()
method changes the string by replacing the old string with a new one.
// replacing "Windows" with ""Educativelet string = "Welcome to Windows";let x = string.replace("Windows", "Educative");console.log(x)