comparing two arrays in javascript returning differences

Solutions on MaxInterview for comparing two arrays in javascript returning differences by the best coders in the world

showing results for - "comparing two arrays in javascript returning differences"
Abdallah
23 Feb 2020
1let difference = arr1.filter(x => !arr2.includes(x));
Axel
06 Jul 2016
1let difference = arr1
2                 .filter(x => !arr2.includes(x))
3                 .concat(arr2.filter(x => !arr1.includes(x)));
4
Philipp
11 Jan 2018
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"]
queries leading to this page
javascript difference of 2 arraysjs difference between two arraysjavascript get the difference between two arraysnodejs difference between two arrayscompare two and get the difference arrays typescriptget diff number between array javascriptarray difference jsjs get diff between arraysjavascript array minus elmeentget difference between two arrays jsfind differences between two arrays javascriptjavascript difference in arrayjavascript difference items in 2 arrayfind similarities betweeen arrays jsarray difference javascriptarray minus array javascripthow to get difference of two arrays of objects javascripthow to take diff of array javscriptget difference between arrays javascripta difference b array javascriptjavascript compare two arrays find differenceswrite a function to return difference between two arrays in javascriptcompare two array and return same data javascriptjs difference of two arraysget difference between 2 arrays javascriptreturning unique differences between two arrayshow to find difference between two arrays in javascriptarray diff function in nodesymmetric difference of two arrays javascriptdifference of two arrays in javascriptjavascript check array differencewrite a function to return difference between two arrays difference two arrays arraysubtract 2 arrays javascriptjavascript show difference between arrayscomparing two arrays in javascript returning differencesjs get different values between arraysarray diff javascriptarray javascript array differenceget diff between two arrays javascripthow to get the difference extra item of array in javascriptdiff two arrays javascriptjavascript compare two arrays for differencesdifference between two arraysreturn symmetric difference of the array javascriptdifference between two arrays in javascriptjavascript find the difference between two arraysjavascript two arrays differencejs get difference between two arraysfind difference between two arrays javascriptcompare two different arrays return with same values javascriptjs find the difference between two arraysdifference with arraycheck 2 arrays for difference 2b javascriptfind difference between two arrays jsdifference in two arrays javascriptget difference between two arrays javascriptjavascript to compare two arrays for additions or subtractions of elementscompare between two arrays javascriptjs find difference between two arraystwo array difference javascripthow to get the difference between two arrays in javascripthow to get difference between two arrays in javascriptcompare two arrays and return the difference javascriptcelsiusvsfahrenheit comparing 2 lists javascriptget difference between two large arrays javascriptarraydiff 28 5b1 2c2 5d 2c 5b1 5d 29 3d 3d 5b2 5d in javascriptfilter two array find the differentjs array differencejs array difference es6difference of two arrays javascriptjavascript difference between arraysjs difference of two arrays of objectreturn difference of two arrays javascriptjavascript two array differencejavascript how to find the symmetric difference of two arrayshow to compare two arrays and get the difference javascriptjs return the difference between two arrayshow find the difference between two arrays jsnodejs find difference between two arraysjavascript get difference between two arraysarray minus array jsreturn difference between two arrays jsfind difference between arrays javascriptknow differnece between two arrays javascriptjavascript diff between arrayjavascript array difffind difference between two arrays in javascriptcompare two arrays and get the difference javascriptjavascript find diff between 2 arraysreturn difference between two arrays javascriptjavascript calculate array difference from two arraysfind differences between two lists nodejshow to find difference between two arrays jsfind the difference between 2 arrays javascriptdifference javascript arraysjs compare two arraysdifferent elements between two arrays javascriptdiffrence jsjavascript check difference between two arraysfind difference of two arrays in jshow to find different elements in two array in jsdifference bewteen two array javascriptdifference between two arrays old javascriptjs get array differencecompare two array values in javascriptjavascript find difference between two arraysjs get difference of two arraysdifference in two arrays javascript es6find the difference between two arrays javascriptcompare two lists and find differences javascriptget difference betwwen arrays jsget diff element between two arraysjavascript subtract array from arrayjavascript compare 2 arrays get difference javascript array differencehow to get the difference of two arrays jsreturn difference of two arrayslist get difference jsnode js array differencejavascript compare two arrays find differences onlinecompare the diff between two arrays and return the diffarray of difference between to arrrays javascripthow to get difference of two arrays in javascriptjavascript diff two arraysfind difference between two array javascriptjavascript difference between two arraysdifference between two arrays jsdifference between two arrays javascriptjs get difference arrayshow to make it different from 2 arrays in jsjs difference arraysjavascript diff in arraydifference of two arrays jsdifference of two array in javascriptcheck the data difference in the array javascriptdifference in two arrays in jsjavascript difference arraydifference in arrays jsjavascript different between arraysjavascript array compare differencedifference between 2 arrays in javascriptarray diffeence 2 jsget array difference javascriptfind difference between two array using filterarray dfference in nodejsget difference between two array javascriptdiff between two arrays javascriptjs two array differencejs array difffind difference between 2 arrays javascriptcalculate the difference of two array in javascriptjavascript differemce between two arraysjavascript array differencejavascript print differences between two arraysarray diff in javascriptjavascript find list difference between two arraysdiff between two array in jsarray difference in javascriptdifrence two arraysfind differences between two arrays jsdifference of array in javascripthow to find different in one array jsget the difference of 2 array javascriptarray diff javascripthow to compare two arrays and return the difference javascriptjavascript compare two arrays and get the differencefind difference between two arrayscompare between 2 array jsdifference between 2 arrays javascriptjavascript diff between two arraysfind difference in two string arrays javascriptjs get 2 array differencejavascript difference two arraysjs diff between arrayscompare 2 arrays and get the difference javascriptjavascript compare arrays obtain differentsget difference of two arrays javascriptjavascript diference two arrayscomparing two arrays in javascript returning differences