title: From two array get unique value in third array in javascript
body: <p>I have two javascript arrays object like below</p>
  
  <p>First array:</p>
  
  <pre><code>count_array[0].left= 0;
  count_array[0].width= 33;
  count_array[0].id= 1;
  count_array[1].left= "";
  count_array[1].width= "";
  count_array[1].id= 2;
  count_array[2].left= "";
  count_array[2].width= "";
  count_array[2].id= 3;
  </code></pre>
  
  <p>Second array:</p>
  
  <pre><code>temp_array[0].left= "";
  temp_array[0].width= "";
  temp_array[0].id= 4;
  temp_array[1].left= "";
  temp_array[1].width= "";
  temp_array[1].id= 5;
  temp_array[2].left= 0;
  temp_array[2].width= 33;
  temp_array[2].id= 1;
  </code></pre>
  
  <p>I want to get array which has unique value of id in javascript from above two array like below</p>
  
  <p>Third array:</p>
  
  <pre><code>temp_array_cnt[0].left= 0;
  temp_array_cnt[0].width= 33;
  temp_array_cnt[0].id= 1;
  </code></pre>
  
  <p>I am using below code but it is not working</p>
  
  <pre><code>function intersection(x,y){
    x.sort();y.sort();
   var i=j=0;ret=[];
   while(i&lt;x.length &amp;&amp; j&lt;y.length){
    if(x[i]&lt;y[j])i++;
    else if(y[j]&lt;x[i])j++;
    else {
      ret.push(x[i]);
      i++,j++;
     }
    }
   return ret;
  </code></pre>
  
  <p>}</p>
  
  <p>Please help me here.
  Thanks</p>
  
  <p>I am using below function now</p>
  
  <pre><code>   function intersection(x,y){
  ret=[];
  //x.sort();y.sort();
  for(var i=0;i&lt;x.length;i++)
  {
   for(var j=0;j&lt;y.length;i++)
   {
      //console.log(x[i].eventid);
      var chk_left=x[i];
      if(chk_left.id == chk_left.id)
      {
          ret.push(chk_left);
      }
   }
  }
     return ret;
     }
  </code></pre>
  
  <p>But it gives me error like this "id is null or not an object".</p>