remove common elements of two arrays in jquery

You can filter array A by checking its elements position in array B:

C = A.filter(function(val) {
 return B.indexOf(val) == -1;
});

Demo


ES6 version of Milind Anantwar's answer. May require Babel.

const A = [1, 2, 3, 4];
const B = [2, 4];
const C = A.filter(a => !B.includes(a));
console.log(C) // returns [1, 3]

Use the Set type from ES6. Then the spread operator to build an array from the Set. A Set type can only hold unique items.

const A = [1, 2, 3, 4];
const B = [2, 4];
const C = [...new Set(A,B)];

console.log(C);



(4) [1, 2, 3, 4]