![]() In addition to using the inline /g, we can use the constructor function of the RegExp object. myMessage.replace(/sentence/g, 'message') If we want JavaScript to replace all, we’ll have to use a regular expression using /g. Normally String replace() only replaces the first instance it finds. Replaces All with literal regular expression Only Replaces One myMessage.replace('sentence', 'message') ![]() ![]() I’ve started building out our JavaScript Glossary and when I got to the replace() method, I had to build out a snippet to handle replacing all occurrences of a string in a string.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |