index.tsx203 chars6 lines
Explanation:
We use the replace()
method on the string sentence
to search for all occurrences of the word "dog" using a regular expression with the g
(global) flag. The second argument is the word "cat", which replaces every occurrence of "dog". Finally, we log the new sentence with the replaced word to the console.
gistlibby LogSnag