title: lodash: filter array of objects with a different array of objects
body: <p>This question is specific to <strong><a href="https://lodash.com/docs" rel="noreferrer">lodash</a></strong>.</p>
  
  <p>Given two arrays of objects, what is the <strong>best way</strong> to filter one array with the objects of the other array? I have attempted to put forth a scenario below, and the way I have gone about doing this is using two <code>.forEach</code> loops, but I would like to know if using lodash there is a better way to go about this type of filtering.</p>
  
  <p><hr>
  <strong>Example</strong><br>
  The main source array of objects is <code>users</code>.</p>
  
  <pre><code>var users = [
    { 'user': 'barney', 'age': 36, 'active': true },
    { 'user': 'joe', 'age': 40, 'active': false },
    { 'user': 'fred', 'age': 50, 'active': false },
    { 'user': 'fred', 'age': 60, 'active': false },
    { 'user': 'fred', 'age': 70, 'active': false },
    { 'user': 'fred', 'age': 22, 'active': false },
    { 'user': 'fred', 'age': 25, 'active': false },
    { 'user': 'barney', 'age': 40, 'active': false },
    { 'user': 'pebbles', 'age': 1,  'active': true }
  ];
  </code></pre>
  
  <p>The array of objects that will filter the <code>users</code> array is called <code>others</code>.</p>
  
  <pre><code>var others = [
    { 'user': 'fred', 'age': 60 },
    { 'user': 'fred', 'age': 70},
    { 'user': 'fred', 'age': 22}
  ];
  </code></pre>
  
  <p>The desired result based on <code>others</code> filtering <code>users</code> is: </p>
  
  <pre><code>[
    { 'user': 'fred', 'age': 60, 'active': false },
    { 'user': 'fred', 'age': 70, 'active': false },
    { 'user': 'fred', 'age': 22, 'active': false }
  ];
  </code></pre>
  
  <p>Here is one way to obtain the desired result. </p>
  
  <pre><code>var result = [];
  
  _.forEach(users, function (n, key) {
     _.forEach(others, function (n2, key2) {
        if (n.user === n2.user &amp;&amp; n.age === n2.age) {
           result.push(n);
        }
     });
  });
  
  console.log(result);
  </code></pre>
  
  <p>Here is the example on jsbin.<br>
  <a href="http://jsbin.com/hapariviya/1/edit?html,js,console,output" rel="noreferrer">http://jsbin.com/hapariviya/1/edit?html,js,console,output</a></p>