title: javascript - remove array element on condition
body: <p>I was wondering how I'd go about implementing a method in javascript that removes all elements of an array that clear a certain condition. (Preferably without using jQuery)</p>
  
  <p>Ex.</p>
  
  <pre><code>ar = [ 1, 2, 3, 4 ];
  ar.removeIf( function(item, idx) {
      return item &gt; 3;
  });
  </code></pre>
  
  <p>The above would go through each item in the array and remove all those that <code>return true</code> for the condition (in the example, item > 3).</p>
  
  <p>I'm just starting out in javascript and was wondering if anyone knew of a short efficient way to get this done.</p>
  
  <p>--<strong>update</strong>--</p>
  
  <p>It would also be great if the condition could work on object properties as well.</p>
  
  <p>Ex.</p>
  
  <pre><code>ar = [ {num:1, str:"a"}, {num:2, str:"b"}, {num:3, str:"c"} ];
  ar.removeIf( function(item, idx) {
      return item.str == "c";
  });
  </code></pre>
  
  <p>Where the item would be removed if <code>item.str == "c"</code></p>
  
  <p>--<strong>update2</strong>--</p>
  
  <p>It would be nice if index conditions could work as well.</p>
  
  <p>Ex.</p>
  
  <pre><code>ar = [ {num:1, str:"a"}, {num:2, str:"b"}, {num:3, str:"c"} ];
  ar.removeIf( function(item, idx) {
      return idx == 2;
  });
  </code></pre>