title: Loop through array when removing elements
body: <p>I'm wondering if and what is a reliable and/or standard way of iterating an array whose length is changing inside the loop. I ask because I end up choosing a different method to do this each time I want to do it, e.g.</p>
  
  <pre><code>for ( var i = 0; i &lt; myarray.length; i++ ) {
    if (myarray[i] === 'something') {
      myarray.splice(i, 1);
  
      // *to avoid jumping over an element whose index was just shifted back to the current i
      i--;
    }
  }
  </code></pre>
  
  <p><strong>or</strong></p>
  
  <pre><code>var i = 0;
  while (myarray[i]) {
    if (myarray[i] === 'something') {
      myarray.splice(i, 1);
    } else {
      i++;
    }
  }
  </code></pre>
  
  <p>These are the ways I find myself doing this, but I'm curious if there is a standard approach.</p>