I am trying to search the text of a body of a webpage against a list of predefined words in an array. Then record how many instances of each word appeared.
<script>
var str = document.body.innerText;
var array = [];
array[0] = "Statement";
array[1] = "Documents";
var regexp = new RegExp( '\\b' + array.join('\\b|\\b') + '\\b').test(str);
document.write(regexp)
</script>
That one is only returning true or false. Or is there a way to make this one work?
var str = document.body.innerText;
var n = str.match(use array here)
document.write(n)
var n = str.match(use array here).length;
– Safirah 8 hours agoinnerText
. UsetextContent
. – Oriol 8 hours agoinnerText
non-standard?innerText
– NonPolynomial 8 hours agoinnerText
used to be non-standard but things have changed now. Hate that MDN redirects you to their cheesy localized page rather than the English version. – GOTO 0 7 hours ago