A cleaner approach in ES6 is the following solution.
var a1 = ['a', 'b']; var a2 = ['a', 'b', 'c', 'd']; Difference
a2.filter(d => !a1.includes(d)) // gives ["c", "d"] Intersection
a2.filter(d => a1.includes(d)) // gives ["a", "b"] A cleaner approach in ES6 is the following solution.
var a1 = ['a', 'b']; var a2 = ['a', 'b', 'c', 'd']; a2.filter(d => !a1.includes(d)) // gives ["c", "d"] a2.filter(d => a1.includes(d)) // gives ["a", "b"]