.replace() Method
Use the .replace()
method to search for a certain string and replace it with another. Take this sentence for example: "Your baby is going to be awesome regardless of it's gender." The sentence is incorrect; it uses the contraction it's (it is) rather than the possessive its. We can fix that using the .replace()
method.
Output
The one important thing to note is that the .replace()
method is set up like so:
The first argument is what you want to replace and the second argument is what you want to replace it with.
By adding g
for global and i
for case insensitive, you can replace any instance of a string, regardless of whether it is upper or lowercase.
Output
Last updated