replace the word "dog" with the word "cat" in the following sentence: "the quick brown fox jumps over the lazy dog." in typescript

Here's how to replace the word "dog" with the word "cat" in the given sentence in typescript:

index.ts
const sentence: string = "the quick brown fox jumps over the lazy dog.";
const replacedSentence: string = sentence.replace("dog", "cat");
console.log(replacedSentence); // "the quick brown fox jumps over the lazy cat."
219 chars
4 lines

The replace() method is called on the sentence string with two arguments; the first argument is the string to be replaced ("dog"), and the second argument is the string to be substituted in its place ("cat"). The method returns a new string with the replacement made.

gistlibby LogSnag