title: How to get array of objects by object and arrays in javascript
body: <p>For the array of object, compare with object and list array using javascript</p>
  <p>should get the array of objects based on below conditions</p>
  <ol>
  <li><p><code>itemvalue and idvalue same</code>, from that check <code>arrobj cid has same codevalue</code> return both array of objects</p>
  </li>
  <li><p><code>itemvalue and idvalue are same</code>, from that check if <code>cid not matching the arraylist</code> and <code>codevalue has value that does not  exist in arraylist</code>, return array of objects</p>
  </li>
  <li><p><code>itemvalue and idvalue same</code>, from that check if <code>codevalue matching the arraylist</code> and <code>cid has value that does not  exist in arraylist</code>, return array of objects</p>
  </li>
  </ol>
  <p>return empty array [] if above fails</p>
  <pre><code>//data1
  var arraylist = [&quot;IN&quot;,&quot;FP&quot;, &quot;FN&quot;];
  var arrobj1 = [
    {id:1, name: &quot;sun&quot;, cid: &quot;IN&quot;, itemvalue: &quot;3456&quot;},
    {id:2, name: &quot;mon&quot;, cid: &quot;FI&quot;, itemvalue: &quot;4567&quot;},
    {id:3, name: &quot;tues&quot;, cid: &quot;SP&quot;, itemvalue: &quot;4567&quot;},
    {id:4, name: &quot;thurs&quot;, cid: &quot;FI&quot;, itemvalue: &quot;2345&quot;},
  ]
  var obj1 = { id:5, name: &quot;ben&quot;, codevalue: &quot;SG&quot;, idvalue:&quot;4567&quot;}
  
  Expected Output
  [
  {id:2, name: &quot;mon&quot;, cid: &quot;FI&quot;, itemvalue: &quot;4567&quot;},  
  {id:3, name: &quot;tues&quot;, cid: &quot;SP&quot;, itemvalue: &quot;4567&quot;}
  ]
  
  ***
  //data2
  var larrylist= [&quot;IN&quot;,&quot;FI&quot;,&quot;FR&quot;];
  var arrobj2 = [
    {id:1, name: &quot;sun&quot;, cid: &quot;IN&quot;, itemvalue: &quot;1234&quot;},
    {id:2, name: &quot;mon&quot;, cid: &quot;FI&quot;, itemvalue: &quot;2468&quot;},
    {id:3, name: &quot;tues&quot;, cid: &quot;IN&quot;, itemvalue: &quot;2468&quot;},
    {id:4, name: &quot;thur&quot;, cid: &quot;FI&quot;, itemvalue: &quot;2345&quot;},
  ]
  var obj2 = { id:5, name: &quot;ben&quot;, codevalue: &quot;SP&quot;, idvalue:&quot;2468&quot;}
  
  Expected Output
  
  []
  
  ***
  
  //data2
  var arraylist= [&quot;IN&quot;,&quot;FI&quot;,&quot;FR&quot;];
  var arrobj3 = [
    {id:1, name: &quot;sun&quot;, cid: &quot;IN&quot;, itemvalue: &quot;1234&quot;},
    {id:2, name: &quot;mon&quot;, cid: &quot;FI&quot;, itemvalue: &quot;2468&quot;},
    {id:3, name: &quot;tues&quot;, cid: &quot;SG&quot;, itemvalue: &quot;2468&quot;},
    {id:4, name: &quot;thur&quot;, cid: &quot;FI&quot;, itemvalue: &quot;2345&quot;},
  ]
  var obj3 = { id:5, name: &quot;ben&quot;, codevalue: &quot;FI&quot;, idvalue:&quot;2468&quot;}
  
  Expected Output
  [
   {id:2, name: &quot;mon&quot;, cid: &quot;FI&quot;, itemvalue: &quot;2468&quot;}
  ]
  </code></pre>
  <p>Tried</p>
  <pre><code>const result = arrobj1.filter((item) =&gt; {
    return item.itemvalue === obj.idvalue &amp;&amp;
      (
        !arraylist.includes(item.cid)
        || item.cid === obj.codevalue
      )
  })
  </code></pre>