title: Count and record partially repeating objects in objects in a new Array Javascript
body: <p>I need to work through a source array of objects, many of the objects in the array have three property values which will be the same. It is these values that will be used to create a new object and push it on to destination array. When another object on the source array comes up with the same three property values as one of the objects on the destination array the matching object on the destination array will have its visit count incremented by one.</p>
  
  <p>To help you understand, in the source array each object is a record of a meal that belongs to a user. In the second array I need to store the user details and the number of their meals.</p>
  
  <p>I've tried a few solutions which have failed like the one below. I thought that the code below would create a literal object, check if it is in the destination array by finding it's indexOf (-1 for not found) and if it's not found push it on. The problem is that it never finds the objects, if I search through 3000 meals the second array ends up 3000 long!</p>
  
  <p>The code below does not try to store the visit count.</p>
  
  <pre><code>userArray = new Array();
  for (var i = 0; i &lt; filteredObjects.length; i++) {
      var user = { 
          forname: filteredObjects[i].forname,
          surname: filteredObjects[i].surname,
          dincat: filteredObjects[i].dincat,
      };
      var index = userArray.indexOf(user);
      if (index = -1) {
          userArray.push(user);
      }
  }
  </code></pre>