How to subtract one array from another, element-wise, in javascript

If you want to find the set difference between two sets, that is, you want all the elements of A that are not in B:

const A = [1, 4, 3, 2]
const B = [0, 2, 1, 2]
console.log(A.filter(n => !B.includes(n)))

If you want arithmetic differences between the elements of A and the corresponding elements of B, then please look to the other posted answers.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)