let a1 = [1,2,3,1,2]; let a2 = [3,4,5,1,2]; const intersction = (s1,s2)=>{ return [...new Set(s1)].filter(item=> { return new Set(s2).has(item) }) } console.log(intersction(a1,a2))