title: How to filter by object property in angularJS
body: <p>I am trying to create a custom filter in AngularJS that will filter a list of objects by the values of a specific property. In this case, I want to filter by the "polarity" property(possible values of "Positive", "Neutral", "Negative"). </p>
  
  <p>Here is my working code without the filter:</p>
  
  <p><strong>HTML:</strong>    </p>
  
  <pre><code>&lt;div class="total"&gt;
      &lt;h2 id="totalTitle"&gt;&lt;/h2&gt;
      &lt;div&gt;{{tweets.length}}&lt;/div&gt;
      &lt;div id="totalPos"&gt;{{tweets.length|posFilter}}&lt;/div&gt;
      &lt;div id="totalNeut"&gt;{{tweets.length|neutFilter}}&lt;/div&gt;
      &lt;div id="totalNeg"&gt;{{tweets.length|negFilter}}&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Here is the "$scope.tweets" array in JSON format:</strong></p>
  
  <pre><code>{{created_at: "Date", text: "tweet text", user:{name: "user name", screen_name: "user       screen name", profile_image_url: "profile pic"}, retweet_count: "retweet count", polarity: "Positive"},
   {created_at: "Date", text: "tweet text", user:{name: "user name", screen_name: "user screen name", profile_image_url: "profile pic"}, retweet_count: "retweet count", polarity: "Positive"},
   {created_at: "Date", text: "tweet text", user:{name: "user name", screen_name: "user screen name", profile_image_url: "profile pic"}, retweet_count: "retweet count", polarity: "Positive"}}
  </code></pre>
  
  <p><strong>The best filter I could come up with as follows:</strong></p>
  
  <pre><code>myAppModule.filter('posFilter', function(){
  return function(tweets){
      var polarity;
      var posFilterArray = [];
      angular.forEach(tweets, function(tweet){
          polarity = tweet.polarity;
          console.log(polarity);
          if(polarity==='Positive'){
                posFilterArray.push(tweet);
          }
          //console.log(polarity);
      });
      return posFilterArray;
  };
  });
  </code></pre>
  
  <p>This method returns an empty array. And nothing is printed from the "console.log(polarity)" statement. It seems like I am not inserting the correct parameters to access the object property of "polarity." </p>
  
  <p>Any ideas? Your response is greatly appreciated.</p>