To replace a substring in a string in JavaScript, you can use the `replace()` method.
In this example,
str
with a value of "Hello World"
.replace()
method to replace the substring "World"
with "Universe"
.str
.let str = "Hello World";
str = str.replace("World", "Universe");
console.log(str);
Hello Universe
In this tutorial, we learned How to Replace a Substring in String in JavaScript language with well detailed examples.