title: Javascript: Finding unmatched objects from 2 arrays
body: <p>I have 2 arrays of objects</p>
  
  <pre><code>var arr1 = [{id: "145", firstname: "dave", lastname: "jones"},
              {id: "135", firstname: "mike",lastname: "williams"},
              {id: "148", firstname: "bob",lastname: "michaels"}];
  var arr2 = [{id: "146", firstname: "dave", lastname: "jones"},
              {id: "135", firstname: "mike", lastname: "williams"},
              {id: "148", firstname: "bob", lastname: "michaels"}];
  </code></pre>
  
  <p>I want to find the objects where the id exists in only one of the arrays and either log the object to the console or push the object to a new array.</p>
  
  <p>Therefore I want to end up with </p>
  
  <pre><code>var arr1 = [{id: "145", firstname: "dave", lastname: "jones"}]
  var arr2 = [{id: "146", firstname: "dave", lastname: "jones"}]
  </code></pre>
  
  <p>I tried using a forEach loop and splicing matching id's out of the array</p>
  
  <pre><code>arr1.forEach(function(element1, index1) {
                  let arr1Id = element1.id;
                  arr2.forEach(function(element2, index2) {
                      if (arr1Id === element2.id) {
                          arr1.splice(element1, index1)
                          arr2.splice(element2, index2)
  
                  };
              });
          });
  
  
  console.log(arr1);
  console.log(arr2);
  </code></pre>
  
  <p>But I ended up with</p>
  
  <p>arr1</p>
  
  <pre><code>[ { id: '135', firstname: 'mike', lastname: 'williams' },
    { id: '148', firstname: 'bob', lastname: 'michaels' } ]
  </code></pre>
  
  <p>arr2</p>
  
  <pre><code> [ { id: '135', firstname: 'mike', lastname: 'williams' },
    { id: '148', firstname: 'bob', lastname: 'michaels' } ]
  </code></pre>