title: Search for all instances of a string inside a string
body: <p>Hello I am using indexOf method to search if a string is present inside another string. But I want to get all the locations of where string is? Is there any method to get all the locations where the string exists?</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script type="text/javascript"&gt;
          function clik()
          {
              var x='hit';
              //document.getElementById('hideme').value ='';
              document.getElementById('hideme').value += x;
              alert(document.getElementById('hideme').value);
          }
  
          function getIndex()
          {
              var z =document.getElementById('hideme').value;
              alert(z.indexOf('hit'));
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;input type='hidden' id='hideme' value=""/&gt;
      &lt;input type='button' id='butt1' value="click click" onClick="clik()"/&gt;
      &lt;input type='button' id='butt2' value="clck clck" onClick="getIndex()"/&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Is there a method to get all positions?</p>