title: How to find difference between two same array in JS?
body: <p>I want to find difference between two arrays. I tried below code from one of the solution given on SF community, but not working from me.</p>
  <p>My below code is not working if there is number repeated EVEN NUMBER of time(like <strong>&quot;7&quot;</strong> repeated twice in both the arrays <strong>a &amp; b</strong> and in result I am getting <strong>&quot;7&quot;</strong> as difference),</p>
  <p>whereas code is working for number repeated ODD NUMBER of time(like <strong>&quot;11&quot;</strong> repeated thrice in both the arrays <strong>a &amp; b</strong> and in result it cancel all the <strong>&quot;11&quot;</strong> and return nothing for this).</p>
  <p>I want the solution to find difference or cancels the number repeated ANY NUMBER of times, I mean if number like &quot;7&quot; repeated twice in both the arrays then it should cancels both the number and return NOTHING.</p>
  <p>And given two arrays are, you can find more examples like &quot;7&quot; and &quot;11&quot; in belows given arrays</p>
  <p>a = [&quot;1&quot;, &quot;3&quot;, &quot;17&quot;, &quot;12&quot;, <strong>&quot;11&quot;</strong>, &quot;17&quot;, <strong><em>&quot;7&quot;</em>, <em>&quot;7&quot;</em></strong>, &quot;85&quot;, &quot;16&quot;, &quot;5&quot;, &quot;30&quot;, <strong>&quot;11&quot;</strong>, &quot;81&quot;, &quot;20&quot;, &quot;49&quot;, &quot;8&quot;, &quot;17&quot;, <strong>&quot;11&quot;</strong>, &quot;8&quot;, &quot;13&quot;, &quot;81&quot;]</p>
  <p>b = [&quot;5&quot;, &quot;20&quot;, &quot;78&quot;, &quot;13&quot;, &quot;85&quot;, &quot;81&quot;, &quot;12&quot;, &quot;17&quot;, &quot;16&quot;, &quot;8&quot;, &quot;17&quot;, &quot;3&quot;, <em><strong>&quot;7&quot;</strong></em>, &quot;1&quot;, <strong>&quot;11&quot;</strong>, &quot;9&quot;, &quot;8&quot;, &quot;17&quot;, &quot;49&quot;, &quot;30&quot;, &quot;81&quot;, <strong>&quot;11&quot;</strong>, <strong>&quot;11&quot;</strong>, <em><strong>&quot;7&quot;</strong></em>]</p>
  <p><strong>Below is the code I am using to find difference between two arays,</strong></p>
  <pre><code>function arr_diff (a1, a2) {
  
  var a = [], diff = [];
  
  for (var i = 0; i &lt; a1.length; i++) {
      a[a1[i]] = true;
  }
  
  for (var i = 0; i &lt; a2.length; i++) {
      if (a[a2[i]]) {
          delete a[a2[i]];
      } else {
          a[a2[i]] = true;
      }
  }
  
  for (var k in a) {
      diff.push(k);
  }
  
  console.log(diff);
  return diff;
  }
  </code></pre>
  <p><strong>DIFFERENCE/RESULT</strong> : I get from two arrays is : [&quot;7&quot;, &quot;8&quot;, &quot;9&quot;, &quot;78&quot;, &quot;81&quot;, &quot;getUnique&quot;]</p>
  <p><strong>EXPECTED RESULT</strong> : from two arrays I want : [&quot;9&quot;, &quot;78&quot;]</p>
  <p>Please help, any help will be appreciated.</p>