- Are the words that you're searching for just single words, or do you mean that you want to search for a phrase? If they are just single words then you can create a complex if-statement, something like this: var word = this.getPageNthWord(p, n); if (word == "WORD1" || word == "WORD2" || word == "WORD3" || word == "WORD4" || word == "WORD5") { // add current and previous pages to the list of pages to delete } - I recommend you use an array where you hold all the page numbers to be deleted and then use a separate loop (again from the last page to the first one!), where you delete all the pages from that array. Also, to make your code more efficient I recommend that when you encounter one of the words you're searching for you stop the internal loop and decrease the value of i by 1, to skip the next (ie, previous) page, because there's no point in searching it if you already know you're going to delete it, is there?
... View more