title: How to delete specific array elements from within a foreach loop in javascript
body: <pre><code>var fruit = ["apple","pear","pear","pear","banana"];
  </code></pre>
  
  <p>How do I remove all "pear" fruit from this array?<br>
  I tried the following, but still one pear remains:</p>
  
  <pre><code>for(var f in fruit) {
      if ( fruit[f] == "pear" ) {
          fruit.splice(f, 1);
      }
  }
  
  for(var f in fruit) {
      document.write(fruit[f]+"&lt;br&gt;");        
  }
  </code></pre>
  
  <p>Outputs:</p>
  
  <pre><code>apple 
  pear 
  banana
  </code></pre>
  
  <p>​What am I doing wrong? Live demo: <a href="http://jsfiddle.net/SbxHc/" rel="noreferrer">http://jsfiddle.net/SbxHc/</a></p>