EN
JavaScript - find symmetric difference of two arrays
0 points
In this article, we would like to show you how to find the symmetric difference between two arrays using JavaScript.

xxxxxxxxxx
1
const array1 = ['a', 'b', 'c'];
2
const array2 = ['a', 'b', 'd'];
3
4
const a = array1.filter((x) => !array2.includes(x));
5
const b = array2.filter((x) => !array1.includes(x));
6
7
const result = a.concat(b);
8
9
console.log(result); // ['c', 'd']