I'm trying to using this JavaScript code:
var aStopWords = new Array ("a", "the", "blah"...);
(code to make it run, full code can be found here: https://jsfiddle.net/j2kbpdjr/)
// sText is the body of text that the keywords are being extracted from.
// It's being separated into an array of words.
// remove stop words
for (var m = 0; m < aStopWords.length; m++) {
sText = sText.replace(' ' + aStopWords[m] + ' ', ' ');
}
to get the keywords from a body of text. It works quite well, however, the issue I'm having is that it only seems to iterate through and ignore one instance of the words in the array aStopWords
.
So if I have the following body of text:
how are you today? Are you well?
And I put var aStopWords = new Array("are","well")
then it seems it will ignore the first instance of are
, but still show the second are
as a keyword. Whereas it will completely remove / ignore well
from the keywords.
If anyone can help ignore all instances of the words in aStopWords
from the keywords, I'd greatly appreciate it.