1let difference = arr1
2 .filter(x => !arr2.includes(x))
3 .concat(arr2.filter(x => !arr1.includes(x)));
4
1function arrayDiff (a1, a2) {
2 var a = [], diff = [];
3 for (var i = 0; i < a1.length; i++) {
4 a[a1[i]] = true;
5 }
6 for (var i = 0; i < a2.length; i++) {
7 if (a[a2[i]]) {
8 delete a[a2[i]];
9 } else {
10 a[a2[i]] = true;
11 }
12 }
13 for (var k in a) {
14 diff.push(k);
15 }
16 return diff;
17}
18//usage:
19console.log(arrayDiff(['red', 'white','green'], [ 'red','white', 'blue']));//["green", "blue"]