JSFiddle - React, Tailwind, and code Playground
JavaScript
/* Creates mechanism that finds a word in a paragraph and replaces it
with another word */
//Declare the original string
var paragraph = "The quick brown fox jumps over the lazy dog";
//Convert paragraph in individual words
var tempArray = paragraph.split(" ");
// Introduce the word to be found; to be replaced
var oldWord = "brown";
// Introduces new word to replace old
var newWord = "red";
//Iterate over the array to find and replace the word
for (var i = 0; i < tempArray.length; i++) {
if (tempArray[i] === oldWord) {
tempArray[i] = newWord;
}
}
/* Reconvert the modified array to string by assigning it to the
original variable */
paragraph = tempArray.join(" ");
// Display your results, it's not an array anymore
console.log(paragraph);