search for text in javascript and get all its start and end index
<p>I have a content like </p>

<blockquote>
  <p>The apple is the pomaceous fruit of the apple tree, species Malus
  domestica in the rose family (Rosaceae). It is one of the most widely
  cultivated tree fruits,  apple is the good for and the most widely
  known of the many members of genus Malus that are used by humans.
  Apples grow on small, deciduous trees.</p>
</blockquote>

<p>I have an array like </p>

<pre><code>["apple", " ", "is", " ", "the"];
</code></pre>

<p>With this array how to find the start index and end index of the word <b>apple is the</b> in javascript?</p>

<p>I tried looping the content and using <code>indexOf</code> but I couldn't get all the index of the word</p>

<p>this is what i tried</p>

<pre><code>var matchs =[];
var content = "a b c defgh a b csdwda abcdfd";
var arrayWord =["a"," ", "b"];
var w =0;
var pos =0;
var firstIndex = content.indexOf(arrayWord[w],pos);
pos = firstIndex;
while (pos &gt; -1) {
    pos+=arrayWord[w].length;
    w++; 
    pos = content.indexOf(arrayWord[w], pos);
    matchs.push(firstIndex,pos);
}
</code></pre>
