diff of two arrays javascript code example

Example 1: javascript difference between two arrays

let difference = arr1.filter(x => !arr2.includes(x));

Example 2: array differenc javascript

let difference = arr1.filter(x => !arr2.includes(x));

Example 3: diff two arrays javascript

function diffArray(arr1, arr2) {
  return arr1
    .concat(arr2)
    .filter(item => !arr1.includes(item) || !arr2.includes(item));
}

Example 4: compare between two arrays javascript

const equals = (a, b) => JSON.stringify(a) === JSON.stringify(b);
let arr1 = ['1','2'];
let arr2 = ['1','2'];
equals(arr1,arr2)//this return false , if not equal then its return false