title: javascript filter array multiple conditions
body: <p>I want to simplify an array of objects. Let's assume that I have following array:</p>
  
  <pre><code>var users = [{
      name: 'John',
      email: 'johnson@mail.com',
      age: 25,
      address: 'USA'
      },
      {
          name: 'Tom',
          email: 'tom@mail.com',
          age: 35,
          address: 'England'
      },
      {
          name: 'Mark',
          email: 'mark@mail.com',
          age: 28,
          address: 'England'
  }];
  </code></pre>
  
  <p>And filter object:</p>
  
  <pre><code>var filter = {address: 'England', name: 'Mark'};
  </code></pre>
  
  <p>For example i need to filter all users by address and name, so i do loop through filter object properties and check it out:</p>
  
  <pre><code>function filterUsers (users, filter) {
      var result = [];
      for (var prop in filter) {
          if (filter.hasOwnProperty(prop)) {
  
              //at the first iteration prop will be address
              for (var i = 0; i &lt; filter.length; i++) {
                  if (users[i][prop] === filter[prop]) {
                      result.push(users[i]);
                  }
              }
          }
      }
      return result;
  }
  </code></pre>
  
  <p>So during first iteration when <code>prop - address</code> will be equal <code>'England'</code> two users will be added to array result (with name Tom and Mark), but on the second iteration when <code>prop name</code> will be equal <code>Mark</code> only the last user should be added to array result, but i end up with two elements in array. </p>
  
  <p>I have got a little idea as why is it happening but still stuck on it and could not find a good solution to fix it. Any help is appreciable. Thanks.</p>