title: How to filter array of objects from keys in javascript?
body: <p>Here, I have one main array called <code>mainArray</code>. In this array I added multiple users list. It can be increased. I can create many group from this <code>mainarray</code>, like group1, group2 and so on. My requirement is, i want to filter objects from <code>mainArray</code>, which haven't added in the groups.</p>
  
  <p>Array main,</p>
  
  <pre><code>var mainArray = [{
    userId: "M000001",
    name: "Jhon",
    companyId: "C0000021"
  }, {
    userId: "M000002",
    name: "Leon",
    companyId: "C0000022"
  }, {
    userId: "M000003",
    name: "Thomas",
    companyId: "C0000023"
  }, {
    userId: "M000004",
    name: "Sean",
    companyId: "C0000024"
  }, {
    userId: "M000005",
    name: "Paul",
    companyId: "C0000025"
  }, {
    userId: "M000006",
    name: "Roldan",
    companyId: "C0000026"
  }, {
    userId: "M000007",
    name: "Mike",
    companyId: "C0000027"
  }, {
    userId: "M000008",
    name: "Mia",
    companyId: "C0000028"
  }];
  </code></pre>
  
  <p>Groups,</p>
  
  <pre><code>var group1 = [{
    userId: "M000004",
    name: "Sean",
    companyId: "C0000024"
  }, {
    userId: "M000005",
    name: "Paul",
    companyId: "C0000025"
  }];
  
  var group2 = [{
    userId: "M000002",
    name: "Leon",
    companyId: "C0000022"
  }, {
    userId: "M000003",
    name: "Thomas",
    companyId: "C0000023"
  }, {
    userId: "M000001",
    name: "John",
    companyId: "C0000021"
  }];
  </code></pre>
  
  <p>Joined group ids,</p>
  
  <pre><code>var joinedGroupIds = ["M000004", "M000005", "M000002", "M000003", "M000001"];
  </code></pre>
  
  <p>The output which i want to be,</p>
  
  <pre><code>var result = [{
    {
      userId: "M000006",
      name: "Roldan",
      companyId: "C0000026"
    }, {
      userId: "M000007",
      name: "Mike",
      companyId: "C0000027"
    }, {
      userId: "M000008",
      name: "Mia",
      companyId: "C0000028"
    }
  }];
  </code></pre>
  
  <p>my javascript code,</p>
  
  <pre><code>var joinGroup, joinedGroupIds = [];
  joinGroup = group1.concat(group2);
  </code></pre>
  
  <p>Concatinated group ids,</p>
  
  <pre><code>joinedGroupIds.map(function(el){
    joinedGroupIds.push(el.userId);
  });
  </code></pre>
  
  <p>Filter objects from main array,</p>
  
  <pre><code>var result = mainArray.filter(function(item) {
    if (joinedGroupIds.indexOf(item.userId) !== -1) return item;
  });
  </code></pre>