comparing array of objects in javascript

Solutions on MaxInterview for comparing array of objects in javascript by the best coders in the world

showing results for - "comparing array of objects in javascript"
Camilla
03 Feb 2018
1// IN THIS EXAMPLE WE HAVE GROUP INSERTS - DATA TO BE ADDED TO DB
2// TO INSERT INTO DB EACH GROUP NAME MUST BE THE MATCHING ID
3// CONATCT NAME MUST ALSO BE MATCHING ID
4// THE CODE BELOW SHOWS HOW TO TRAVERSE THROGUH TWO ARRAYS AND COMPARE / ADD VALES
5
6const groupInserts = [ { groups: [ 'Chess', 'Science', 'German' ], name: 'Ian Smith' },
7  { groups: [ 'Swimming' ], name: 'Jenny Smith' },
8  { groups: [ 'Tennis' ], name: 'Susan Jones' },
9  { groups: [ 'Coding', 'Science' ], name: 'Judy Davis' } ]
10
11const nameAndIdsFromDB = [ { name: 'Parent_1', id: 1 },
12{ name: 'Parent_2', id: 2 },
13{ name: 'Ian Smith', id: 99 },
14{ name: 'Jenny Smith', id: 100 },
15{ name: 'Susan Jones', id: 101 },
16{ name: 'Judy Davis', id: 102 } ]
17
18const groupnameAndIdsFromDB = [ { name: 'Debugging', id: 1 },
19{ name: 'React', id: 2 },
20{ name: 'New record with no people', id: 3 },
21{ name: 'New record with people', id: 4 },
22{ name: 'Chess', id: 12 },
23{ name: 'Science', id: 13 },
24{ name: 'German', id: 14 },
25{ name: 'Swimming', id: 15 },
26{ name: 'Tennis', id: 16 },
27{ name: 'Coding', id: 17 } ]
28
29let groupNamesWithIds = [];
30groupInserts.forEach(data => {
31    if (data.groups) {
32         data.groups.map(e => {
33                let obj = {};
34                obj.group = e;
35                obj.name = data.name
36                groupNamesWithIds.push(obj);
37        })
38    }
39})
40
41
42let addedMessageGroupIds = [];
43groupNamesWithIds.forEach(data => {
44  groupnameAndIdsFromDB.map(e => {
45    if (e.name === data.group) {
46      addedMessageGroupIds.push({group: data.group, name: data.name, messages_individual_groups_id: e.id})
47    }
48  })
49})
50
51let addedContactIds = [];
52addedMessageGroupIds.forEach(data => {
53  nameAndIdsFromDB.map(e => {
54    if (e.name === data.name) {
55      addedContactIds.push({messages_individual_groups_id: data.messages_individual_groups_id, contact_id: e.id, created_at: Date.now()})
56    }
57  })
58})
Sophie
28 May 2018
1a = [{ value:"4a55eff3-1e0d-4a81-9105-3ddd7521d642", display:"Jamsheer"}, { value:"644838b3-604d-4899-8b78-09e4799f586f", display:"Muhammed"}, { value:"b6ee537a-375c-45bd-b9d4-4dd84a75041d", display:"Ravi"}, { value:"e97339e1-939d-47ab-974c-1b68c9cfb536", display:"Ajmal"},  { value:"a63a6f77-c637-454e-abf2-dfb9b543af6c", display:"Ryan"}]
2b = [{ value:"4a55eff3-1e0d-4a81-9105-3ddd7521d642", display:"Jamsheer", $$hashKey:"008"}, { value:"644838b3-604d-4899-8b78-09e4799f586f", display:"Muhammed", $$hashKey:"009"}, { value:"b6ee537a-375c-45bd-b9d4-4dd84a75041d", display:"Ravi", $$hashKey:"00A"}, { value:"e97339e1-939d-47ab-974c-1b68c9cfb536", display:"Ajmal", $$hashKey:"00B"}]
3
4function comparer(otherArray){
5  return function(current){
6    return otherArray.filter(function(other){
7      return other.value == current.value && other.display == current.display
8    }).length == 0;
9  }
10}
11
12var onlyInA = a.filter(comparer(b));
13var onlyInB = b.filter(comparer(a));
14
15result = onlyInA.concat(onlyInB);
16
17console.log(result);
queries leading to this page
array compared with array of object javascriptcompare two array object using typescript return true listfilter an object of values from two arrays of values for each in javascriptjavascript compare array values with values of object array 2c if a single value matches 2c return truehow to compare array objects with stringjavascript comparing array of objectscompare values of array in object javascriptcompare array of objects to an elementes6 compare two arrays of objectsjs find different keys in two arrayscompare array of objects javascriptjs compare two array of objectscompare two arrays javascript objectscompare array in object with another array in objectjavascript difference array of objectscompare two array of objects javascript es 5compare similar data in two array of objects in javascriptget value from array of objects javascript and compare it with some valuecompare two objects arraycompare array with object in javascriptcompare non identical objects in array javascriptcompare any one object within arrayi have an array of objects how do i compare values within each object in javascirptjs compare 2 array of objectsecmascript 2b array of object comparisonjavascript compare two arrays of objects for differencescompare array values to object valesutwo arrays of objects comparejavascript check if object is equivalent along with values to array of valuesjavascript compare array objectscompare multiple objects in javascript arrayhow to compare 2 objects in one javascript arrayget difference between two object arrays javascriptcomparing array of objects with string in javascript loookes6 compare 2 arrays of objectsget different object from two arraycompare if two array of objects are equalhow to compare one array of objects in javascriptarray of objects compare if differentcomparing array of objects in jshow to compare two object of array is samehow to compare to array of objectscompare array of objects javascript keep matchesjavascript compare two arrays of objects for equalitycompare objects in an array javascriptcompare two array of objects in javasciptcompare two objects in an array of object jscompare two array of different objects es6compare two array object datajs compare 2 arrays of objectshow to compare values in 2 array of objects in jsget diff value of a field in array of object javascriptcompare array of object values javascriptjavascript compare two object arrayscompare 2 array of objects in js with o 28n 29 complexitycomparing arrays of objects javascriptcompare two objectid arrays in javascript es6js compare properties two arrays of objectscompare objects in same array javascriptjavascript two objec array comparejavascript compare two arrays of objects find differencescompare values inside an array of objectscompare arrays of objects return same values javascriptcomparing each element of array objectcompare array object any arry of values in javascripthow to get difference of two arrays of objects javascriptcompare two object with every javascriptobject array javascript comparejs compare array of objects with different propertiesjavascript compare two arrays of objects for matcheshow to check if two arrays of objects are equalfind the difference between two list angularjavascript compare array of objects by idcompare two arrays with objects jshow to compare two items in one array js 22javascript 22 22es6 22 difference of two objects include arraysget object by comparing arrayjavascript two array find new items 22javascript 22 difference of two objects include arraystypescript compare two arrays of objects return differencecompare arrays of objects javascriptdifference between complex and simple arrays in javascriptcompare objects in arrayjavascript check compare every item in two objects for differencescompare two arrays of objects javascript return similarjs compare arrays of objecthow to compare object array in javascriptcompare arrays of objects if eacheasy way to compare two array of objects in javacsriptcompare array with objevtangular array equals arrayhow to compare arrays with objects jsjavascript compare two array objects valuescompare two objects in two arrays javascriptcompare two array javascript return false if diffirentcompare whole array of objects javascript with array of objectsjavascript compare values array or objectcompare 2 arrays of objects how to check both are equal in array of objectscompare two object arrays in javascriptcomparing two array of objects in javascript returning differencescompare two objects in one array of objects javascriptcompare two objects in an array of objects javascriptjavascript difference in array objectshow to compare two objects in array of object in jsarray with object comparehow to compare two array often objects in javascriptcompare array objects javascriptjs two arrays of objects compare valuesfilter array and return difference typescriptjavascript difference of two objects include arraysjs compare objects in arraycompare two lists angular8compare values from 2 array objectscompare multidimensional aray javascript changesjavascript how to compare 2 object arrayscompare an array of objects with another array javascriptmap over array of objects compare objects javascriptjs compare object values with arrayjs array compare to previous objectcan i have an array of objects and compare sub elementsget objects that are not included in two arrayscompare array object javascriptjs compare array of objectscomparing two arrays of objectas javascriptjavascript in two or more array compare element and get only elements present in all arraycompare two arrays javascript unorderedhow to get the difference between two arrays of objects in typescriptjavascript compare two arrays have same elementscompare object in two arraycompare particular elements in two arrays javascripthow to compare two objects inside an arrayjs compare to arrays of object and get matching objectsfilter two objects compare javascriptpass in two arrays as objectscheck if 2 array of objects are equal javascriptjs compare objects of 2 arraysarray of objects compare value javascriptjavascript check if two arrays of objects have same elementscomparing array objects of entire arrayhow to compare same array of objects in javascriptjs difference of array of objects es6how to compare two array of objects javascriptcompare array with array of objects javascriptcompare two arrays with objects javascripttypescript compare two object arraysdiff between two arrays of object typescriptarray object type comparison javascriptarrays vs objects differences javascriptjavascript typescript compare two arrays of objectscompare object array number with valuefind 2 array of objects is same in javascriptjavascript 2b compare array of objects and get differencejavascript compare arrays of objectsjs compare array of objects and return arraycompare two arrays of objects and return the identicalsjavascript compare 2 arrays of objectscompare two objects in javascript es6 and extract the same itemsjavascript compare 2 array of objectsjs make new arrays where objects have same valuejavascript array compare objectscompare array of string with array of objects javascriptcompare arry of object and creat a new array of objectjavascript compare object arrayscompare 2 objects arrays are equal javascriptjs find diff arrays of objectsjs compare tow array with objectsjavascript array equalshow to compare objects from different arrays javascripthow to compare two object arrays in javascripthow to compare two array of objects in node jscompare items in array javascriptlodash difference between two arrays of objectsarray of objects equal to some od jsarray of object comparison in javascriptcompare array objects value with array javascriptcompare two objects in same array jscompare objects data in array javascriptcompare two arrays of objects and return the difference javascripttwo array of objects find difference betweencompare array of objectshow to compare two arrays of objects in javascripthow to compare array of objects in javascriptjavascript difference of two arrays of objectscompare is same array of objects javascriptfilter between two objects and replacecompare two properties from array of objects javascript es6comparing two objects in javascriptjavascript check if two arrays of objects are equalcompare two arrays of objects that are not the same javascripthow to find difference between two array of objects javascriptcompare properties in two arrays ecmascriptcompare arry of objects javascriptfilter two array of objects javascriptcompare two arrays objects javascripthow to compare array and array of objects in javascriptcompare array objects in javascriptcompare arrays of objectshow to compare to array of objects in jscompare object array jsjs check differences in arrays of objectsjs compare list of objects with list of stringshow to compare a array of object values in jsuncommon elements between two object arrays javascriptget object array value and comparehow to make an array of objects see if they are in the same arrayget differences between two arrays with objectscompare objects in two arrayjs compare array of objects with another arrayofobjectcomparee data witihin array of objectsjavascript compare two arrays using objectshow to compare two array and make an objectcompare 2 objects in arrayjavascript compare two object arrays return differencejavascript compare two aobject from arraynodejs compare array of objectscompare value of objects in an array with an array of stringjavascript compare to arrays of objectscompare object arrays javascriptcomparing two arrays of objects in javascriptcheck if array with objects have the same contentcomparing array of objects in javascripthow to compare array of objectjs compare to array of object and get matching objectscompare two object arrays javascript by values and return matchescompare two array of objects jshow to compare array of object in javascriptlodash difference between two arrays based of keyget objects that are not included in two arrays angularfind the different item in an array javascriptcomparing a value between two array objects javascripthow to compare to array of objects and return matched objectsjavascript compare two arrays with objects if equalcompare values inside object inside array in nodecomparing each object of array javascriptcompare two object of a array jsarray of object compare 2 properties identical from different objectjavascript compare array of objectshow to check two array of objects have same propertyhow to compare 2 arrays of objects and return the difference javascripthow to find difference between two array of objects javascript with unique valuecomparing two array of objects in javascriptcompare object array to object javascripthow to compare all objects of arraycomparing an array with an array objectcompare 2 array of objects are equal or not in node jsjavascript compare two arrays of objects for matching valuescheck similarity between two arrays of object javascriptcompare two arrays with objectshow to compare object properties in arrayjavascript compare 3 arrays of objectshow to compare two different array of objects in javascriptcompare the value object inside the arrayget item not define in two arrayhow to compare two values in an array of objects javascriptcompare values of array inside objectcheck if two array of objects are equal javascriptcompare diff 2 array object javascriptjavascript compare two arrays of objects return differencejs compare 2 object arraysfind the difference between two arrays of objectsjavascriptjavascript fastest way to compare array of objectscompare two array of dictionary jsfind difference between two array of objects javascriptcompare two arrays object javascriptarray of objects javascript compareget diff value of same field from array object javascriptcomparing two array of objects javascripthow to compare 2 object arrays in javascriptjavascript compare elements array of objectscompare two array of objects javascript es6difference between two array of objects orderjavascript compare two array of objectscompare two objects for properties in same array jscompare multiple objects in a single array javascriptjavascript difference of two objects with arrayscompare objects of same array javascriptcompare one object of aarray with other in es6compare two array object values in javascriptcompare two arrayz of objectshow to check if array of object is equal array of object javascriptangular compare two arrays of objectscompare array of object property to array of values jscompering inside an array javascriptdifference between 2 lists of objects in angular 8how to compare two array of objects in and return combine objectget diff between two object arraynodejs compare 2 array of objectscompare objects in single array javascriptcompare 2 arrays javascript with objectobject and array array compare javascriptcompare single array of objects javascripthow to compare array of objects with string in javascriptcheck if 2 array object have same valuecompare two arrays of objects javascript return 1 if true compare object and array in javascriptjavascript diff arrays of objectshow to compare 2 arrays of objects in javascriptcompare array of objects with object javascriptcompare data within array of objects javascriptarray object compare javascripthow to compare two array of objects in javascripthow to compare array of object with normal array in javascripthow to compare objects inside an array according to valuehow to compare two array of objects in jsjavascript compare two array of objects for matchescompare value of objects in an array with an arraycheck the difference between two array of objectsjavascript compare two arrays with objesctsobject and array compare javascripthow does includes 28 29 compare arrays of objects javascriptcompare values of array in objects javascripthow to compare array of obj element in javascripthow to compare objects array with single object javascriptcompare array object in javascriptjavascript match two arrays of objectseasy way to compare two array objects in javascriptcompare two objects in an array compare two array of objects in javascript es6how to check equl two arrays inside valuehow to compare 2 array of objects in javascripthow to compare between two arrays based on one parameter in jsfilter two arrays of objects javascriptcompare 2 array of object return same elementshow to compare two array of object with value in jsequals object array jshow to compare objects in arrays if they have same values in jscomparing between two arrays of objectscompare 2 array of objects in javascripthow to compare array of object in find in nodejscompare object with array of objects javascriptcompare array of objectcompare object array javascripthow to compare two arrays of object is samejs array of objects compare each otherfind difference between two arrays of objects javascriptcompare 2 array of objectscompare object and array javascriptjs comparing array of objectscompare list of objects with list of strings jscomparing objects in arraycompare arrays of objects jscheck if array of objects are equal javascripthow to compare 2 array objects and returning a value in javascriptfilter two array of objects find the differenttypescript compare arrays of objectscompare two array of objectshow to compare 2 arrays containing objects in javascriptcheck if two arrays of objects are equal javascriptjav acrpit compare array of objectsjavascript check in array two objects equalhow to compare elements of two arrays of different objects in javascript then make a new array with the differencesjavascript object compare with arraycompare array of object in jsjs compare arrays of objectsecmascript 2b array of objects comparisondiff between 2 non primitive arrays nodejsfind the difference between one object and other jsjs see if 2 arrays of objects contain an equal valuebest way to compare object arrayshow to compare object data with array jsdifference of two arrays objects javascriptcomparing element of arrays and object inside arraytypescript compare two arrays of objectscompare array with object jsdiff between object and arraycompare 2 array object javascript with idcompare two arrays and get diferent with objects javascriptcompare array values to object values javascriptfind differences between two arrays with objects jsarray of objects compare javascriptgo over array and compare object values javascriptcompare object value with array value compare objects array javascriptcompare 2 arrays with objectshow to compare an array of objects in javascriptlodash difference between two arrays based on keycompare two array objects javascriptjavascript compare array values with values of object arraycompare two arrays of objects and get the difference javascriptarray of object compare 2 value from different objecthow to compare 2 array objects in javascriptjavascript compare each objects in an arraydeep compare array of objects javascriptcompare two arrays of objects by property jscompare two array and select odd data in typescriptcompare a number with values in array javascriptcompare two arrays of objects javascriptcomparing objects in an arraycomparing 2 arrays returns falsejs compare two arrays of objectsget the object difference in two arrays javascriptarray of objects difference javascriptcomparing 2 object in arraycompare object array and array js comparing values from the array of objectscheck if array of objects is equal javascriptjs compare two arrays of objects for matchescompare specific property from array of objects javascripthow to compare array of objects in javascriptjavascript compare 2 object arraysjavascript compare each objects in 1 arraycompare value in 2 array of objects javascriptget differences in array of objectsconst result 3d 2 in arraycompare two arrays and array of objects javascript es6javascript compare objects in 2 arraycompare array of objects against array of stringshow to compare two arrays or objects in jshow to compare two arrays of different data javascripthow to comparing arrayhs of objects to a object javascriptfilter two object based array jscompare two array of objects javascript examplefilter an object of values from two arrays of values in javascripthow compare a value between 2 values in javascript they may be vice versacompare two arrays of objects jscompare two object and get the same objects in a new arrays jscompare two objects array javascriptcompare array and object in javascriptjs compare arrays which has objectjs deep compare objects in arrayhow to compare to arrays of objects and get the values that are not in both array of objects javascirptjavascript 2b array of objects comparisoncompare 2 arrays of objects javascriptcompare two array of objects es6compare array of objects with array of objectscompare 2 arrays javascript get the same objectscompare an array of objects with another javascripthow to find the difference between two arrays of objects in javascriptcompare two array of objects in javascriptcompare array of objects value jscheck if array of objects are equalsjavascript difference between two arrays of objectsget two elements from array and compare arrays objects javascriptequality check for array of objects javascriptwhy cannot compare array and objects with 3d 3d 3d jscompare object with same values in list jscompare prop of two array of objects javascript es6how to compare arrayof object imn java scriptreact find difference between 2 objectsjs array equals objectcomparing two arrays of objects in javascript returning differencescompare two arrays objectcompare two array of object and return unmatched elementshow to compare values in different objects within the same array javascriptjavascript filter between two objets determine if same keyhow to compare two array objects in javascripthow to compare 2 same values in array of objects in javascriptcompare two array objects in javascriptget list array difficult in two array in typescriptcompare any one object within array in nodecompare array of objects 2 valuescomparision two array of objectcompare values of array of objects javascriptjavascript compare two arrays of objectsjs array of objects comparefilter two object arrays javascriptjs compare two arrays for equal objectscompare array of javascript objectsjavascript compare nnumber in array get in between objectshow to filter two array of objects in javascriptjavascript compare two sales array of objectshow to compare object array with in itselfhow to compare an object property in an array to the next element javascripthow to compare two arrays of object in javascriptjavascript compare two arrays of objects for matches es6compare two object arrays es6find difference between 2 arrays of objects javascripttypescript compare array of objectscompare array objects props in javascriptcompare redundancy between two array objects javascriptjs compare list of objectshow to compare values in array of object javascripthow to compare object with each object in array javascriptcompare two array of objects javascriptcompare two arrays of objects and find differencecompare values in object array javascriptget difference between two arrays of objects javascriptcompare single value on array of objectget the difference of two lists angular 8compare two different array of objects in javascriptjabvascriipt compare two objects from arrayjavascript check if two array of objects have same elementscompare objects in array javascriptcomparing arrays of objects in javascripthow to compare objects in array javascriptget difference between two array of objects javascriptwrire compare function to compare array of objects javascripthow to compare two objects in an array javascrpihow to compare between two arrays based on one parameterjavascript object array comparehow to check if 2 array of obhects are samejavascript compare array of dictionariesdifference between two arrays of objects javascriptcompare objct in arrayjs compare array and on objecthow to compare objects within array javascript compare two arrays of objects and display get diff value of a field in array of objects javascriptarray of objects compare each itemcompare two arrays of objects in javascriptcompare and array of objects with an obejctcompare two arrays of objects are equal javascripthow to compare value with array of objects javascripthow to compare two objects of an array in javascriptjavascript compare array of objects same valuenode js difference between two arrays of objectcompare 2 object arrays javascriptreturn object where equel values in objects of the arraycompare items in an object with items in an array javascripthow to compare two arrays of objects in javascript and get differences field into one array js compare objects array between themcompare multiple objects in a single arrayjavascript compare array of objects containscompare 2 array of objects javascriptjavascript compare array of object es6javascript compare objects for match in two different arraysjavascript 2b compare array with object and return fields in objectjavascript compare values in array of objectjs compare equality between two arrays of objectshow to compare objects properties in array javascripthow to compare items in array against each other jsequality of arrays with objects javascriptcompare values in array javascripthow to compare two values of objects in different arraycheck equality objects and array s javascriptcomparing array of objects in javascript