Find all indexes of substrings in a string and respective limits with javascript : <p>I need a function that would return information on the position of substrings in a larger string with javascript. I don't know if something like this exists natively so I want to take my chances here.</p>

<p>For example, having the following input string:</p>

<p><code>"dog elephant you me test another test what thesis"</code></p>

<p>And if I have the following array:</p>

<p><code>array("Dog", "test", "not this one", "what the heck", "thesis")</code></p>

<p>What is the most efficient way to <strong>indexOf</strong> the position of all these elements in the input string? Having the function return an object with information like this:</p>

<ul>
<li>"Dog" - from 0 to 3</li>
<li>"test" - from (where <code>test</code> begins) to (where it ends)</li>
<li>"not this one" - null (not in the string)</li>
<li>"what the heck" - null (not in the string)</li>
<li>"thesis" - from (where <code>thesis</code> begins) to (where it ends)</li>
</ul>

<p>Does anyone have any idea?
Tyvm!</p>
