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.
Practical example
// ONLINE-RUNNER:browser;
const array1 = ['a', 'b', 'c'];
const array2 = ['a', 'b', 'd'];
const a = array1.filter((x) => !array2.includes(x));
const b = array2.filter((x) => !array1.includes(x));
const result = a.concat(b);
console.log(result); // ['c', 'd']