title: Select Objects in Array Based on Regex Match
body: <p>How can I return only the objects in an array that meet a certain criteria using javascript?</p>
  
  <p>For instance, if I have ['apple','avocado','banana','cherry'] and want to only output fruit that begin with the letter 'A'.</p>
  
  <p>EDIT:</p>
  
  <p>Took Sean Kinsey's function below and tried to make it more flexible by passing in the array and letter to match:</p>
  
  <p>function filterABC(arr,abc) {</p>
  
  <pre><code>var arr = arr;
  
  var filtered = (function(){
      var filtered = [], i = arr.length;
  while (i--) {
      if ('/^' + abc + '/'.test(arr[i])) {
      filtered.push(arr[i]);
      }
  }
  return filtered;
  })();
  
  return filtered.join(); 
  </code></pre>
  
  <p>}</p>
  
  <p>Trying to call it with filterABC(arr,'A') or filterABC(arr,'A|B|C|') to output all matches from A to C but having trouble with this part.</p>