Looking to prefix words in a string that match specific 'filter' words with a # symbol.
Here's what I've tried:
let wordsArray = ['she', 'smile'];
let sentence = 'She has a big smile';
let sentenceArray = sentence.split(" ");
wordsArray.forEach((word, index) => {
sentenceArray.forEach((sWord, sIndex) => {
if (sWord === word) {
sentenceArray[sIndex] = `#${sWord}`;
console.log(sentenceArray);
}
});
});
Here's the output in the console.
app.js:17 (5) ["She", "has", "a", "big", "smile", She: "#She"]
app.js:17 (5) ["She", "has", "a", "big", "smile", She: "#She", has:
"#has"] app.js:23 She has a big smile
Any suggestions on where the issue might be?