var array1 = ["AL", "CA", "IN "];
var array2 = ["AL", "AL", "CA", "CA", "IN", "IN", "WI", "WY"];
My desired o/p:
["AL", "CA", "IN"]
var array1 = ["AL", "CA", "I"];
var array2 = ["AL", "AL", "CA", "CA", "IN", "IN", "WI", "WY"];
My desired o/p:
["AL", "CA"]
I tried like this:
const intersection = array1.filter(element => array2.includes(element));
console.log(intersection)
But i am getting o/p : ["AL", "CA"]
. Can some one help me on this.
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.