Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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)
share|improve this question
    
Try doing var n = str.match(use array here).length; – Safirah 14 mins ago
2  
Also check out this question: stackoverflow.com/questions/1072765/… – Safirah 12 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.