title: Modify collection while looping through it
body: <p>I have a collection of objects in TypeScript.  Each object has a method called <code>getSubObjects</code> which returns a collection of objects of the same type containing the same method <code>getSubObjects</code>.  My requirement is</p>
  
  <ol>
  <li>Have to iterate through the original collection calling <code>getSubObjects</code> of each object in the collection.</li>
  <li>For each object returned call <code>getSubObjects</code> again.</li>
  <li>Keep on going for each object returned until there is no object</li>
  </ol>
  
  <p>So in my loop I want to do something like the following</p>
  
  <pre><code>objCol.forEach(item =&gt; {
    const col = item.getSubObjects();
    if(col){
        objCol.pushRange(col)
    }
  });
  </code></pre>
  
  <p>I don't think this is possible in TypeScript, the only alternative I can think of is to resort to recursion, but I would rather avoid it if there an alternative way in which I can do this.</p>