title: $.grep to check if object exists in array
body: <p>I am trying to build an array of objects and then either update the object or create a new one depending if one does not exist. This is my first time trying to use the $.grep function and I am not sure what I am doing wrong. Any Advice?</p>
  
  <p>Here are the objects:</p>
  
  <pre><code>function Phase(phase, html, count) {
          this.phase = phase;
          this.html = html;
          this.count = count;
          this.porfolios = [];
      }
  
      function Portfolio(portfolio, html, count) {
          this.portfolio = portfolio;
          this.html = html;
          this.count = count;
      }
  </code></pre>
  
  <p>Here is the code in question....</p>
  
  <pre><code>var phases = [];
  //Check Array of Phases 
  result = $.grep(phases, function (e) { return e.phase == item.Phase; });
  
  if (result.length == 0) 
  {
       var newphase = Phase(item.Phase, itemhtml, 1)
       phases.push(newphase);
  } 
  else if (result.length == 1) 
  {
   // update existing phase
   result[0].count ++;
   result[0].html += itemhtml;
  }
  </code></pre>