The replace method returns a new string with the new substring you add as a parameter included in place of the other substring that you add as a parameter to be replaced.
Here is an example of the method being used:
var poem = "She sells seashells by the seashore. The shells she sells are surely seashells."
// replace all the sea with ocean
poem = poem.replace("sea", "ocean")
poem = poem.replace("sea", "ocean")
poem = poem.replace("sea", "ocean")
console.log(poem);
// -> She sells oceanshells by the oceanshore. The shells she sells are surely oceanshells.
Top comments (1)
why not just do
poem.replaceAll("sea", "ocean")
?