title: Compare 2 arrays and filter matched elements
body: <pre><code>var array1 = [&quot;AL&quot;, &quot;CA&quot;, &quot;IN &quot;];
  var array2 = [&quot;AL&quot;, &quot;AL&quot;, &quot;CA&quot;, &quot;CA&quot;, &quot;IN&quot;, &quot;IN&quot;, &quot;WI&quot;, &quot;WY&quot;];
  </code></pre>
  <p>My desired o/p:</p>
  <pre><code>[&quot;AL&quot;, &quot;CA&quot;, &quot;IN&quot;]
  </code></pre>
  <ol start="2">
  <li></li>
  </ol>
  <pre><code>var array1 = [&quot;AL&quot;, &quot;CA&quot;, &quot;I&quot;];
  var array2 = [&quot;AL&quot;, &quot;AL&quot;, &quot;CA&quot;, &quot;CA&quot;, &quot;IN&quot;, &quot;IN&quot;, &quot;WI&quot;, &quot;WY&quot;];
  </code></pre>
  <p>My desired o/p:</p>
  <pre><code>[&quot;AL&quot;, &quot;CA&quot;]
  </code></pre>
  <p>I tried like this:</p>
  <pre><code>const intersection = array1.filter(element =&gt; array2.includes(element));
  </code></pre>
  <p>console.log(intersection)
  But i am getting o/p : <code>[&quot;AL&quot;, &quot;CA&quot;]</code>. Can some one help me on this.</p>
  <p>I want to compare 2 arrays and find the result with matched elements,I searched a lot but could not get a solution .please help me in advance.</p>