In this article we will learn how to replace word in a string.
Imagine you have a string like this:
And you want to replace "World" with "John"
How to solve this problem?
Well, the solution to this problem is easy, especially with a function like
Replace word in string with
We can use
replace() method to replace word in string.
// String const myString = "Hello World" // Replace const result = myString.replace("World", "John") // Print Result: console.log(result);
replace() method returns a new string with one, some, or all matches of a pattern replaced by a replacement.
Thank you for reading
Thank you for reading my blog. 🚀