A more simpler approach is: if you consider that a word is something like
"My pc there is ram memory" (between spaces)
you could concat into your indexOf function spaces before and after the word that you are searching, like this
if (sentence.indexOf(" "+ word +" ") >= 0) {