1function diffArray(arr1, arr2) {
2 return arr1
3 .concat(arr2)
4 .filter(item => !arr1.includes(item) || !arr2.includes(item));
5}
1const equals = (a, b) => JSON.stringify(a) === JSON.stringify(b);
2let arr1 = ['1','2'];
3let arr2 = ['1','2'];
4equals(arr1,arr2)//this return false , if not equal then its return false
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"]
1function arraysAreIdentical(arr1, arr2){
2 if (arr1.length !== arr2.length) return false;
3 for (var i = 0, len = arr1.length; i < len; i++){
4 if (arr1[i] !== arr2[i]){
5 return false;
6 }
7 }
8 return true;
9}