0
I’m creating code for a Chrome extension where I want to take all the text present on the page of any site, put it in an array, and compare it to a pre-existing array of specific words. I can take the words on the page and put them in an array for comparison, but when it comes to presenting the intersection between the two, it returns an empty array. And these are words present on the page I’m testing.
Does anyone know what the problem might be? Follow the code:
function check() {
let badWords = ['Spot', 'Cakes', 'Work'];
console.log(badWords);
let pageWords = [];
pageWords.push(document.documentElement.textContent.split(' ') || document.documentElement.innerText.split(' '));
console.log(pageWords);
let gotYou = badWords.filter(a => pageWords.includes(a));
console.log(gotYou);
}
check();`
Even test if the word exists with an index, and returns true.
console.log(pageWords.indexOf('Work↵') > -1);