Let’s say we have a variable,
text, assigned to a
let text = "the cat sat on the mat";
We want to replace the word “the” with the word “no”.
string has a nice
text = text.replace("the", "no");
text variable now contains the value “no cat sat on the mat”. This perhaps isn’t what we’d hoped for - only the first “the” has been replaced.
The first, parameter in the
replace method can actually be a regular expression which we can use to specify that we want to replace all the instances of the matched word:
text = text.replace(/the/g, "no");
g at the end of the regular expression tells the
replace method to match all instances.
text variable now contains the value “no cat sat on no mat”. Great - we managed to replace all the instances of “the” with “no”!
📺 The video in this post was made by Programming with Mosh
The origin of the article: https://www.youtube.com/watch?v=09BwruU4kiY&list=PLTjRvDozrdlxEIuOBZkMAK5uiqp8rHUax&index=6
🔥 If you’re a beginner. I believe the article below will be useful to you ☞ What You Should Know Before Investing in Cryptocurrency - For Beginner
⭐ ⭐ ⭐The project is of interest to the community. Join to Get free ‘GEEK coin’ (GEEKCASH coin)!
☞ **-----CLICK HERE-----**⭐ ⭐ ⭐
Thanks for visiting and watching! Please don’t forget to leave a like, comment and share!
Does your business need an interactive website or app?
The technology used to develop the overall app by the developers from WebClues Infotech is at par with the latest available technology.
For more inquiry click here https://bit.ly/31eZyDZ
Book Free Interview: https://bit.ly/3dDShFg