showing results for - "match ids from 2 arrays in javascript asynchronous programming"
Till
23 Nov 2020
1var result1 = [
2    {id:1, name:'Sandra', type:'user', username:'sandra'},
3    {id:2, name:'John', type:'admin', username:'johnny2'},
4    {id:3, name:'Peter', type:'user', username:'pete'},
5    {id:4, name:'Bobby', type:'user', username:'be_bob'}
6];
7
8var result2 = [
9    {id:2, name:'John', email:'johnny@example.com'},
10    {id:4, name:'Bobby', email:'bobby@example.com'}
11];
12
13var props = ['id', 'name'];
14
15var result = result1.filter(function(o1){
16    // filter out (!) items in result2
17    return !result2.some(function(o2){
18        return o1.id === o2.id;          // assumes unique id
19    });
20}).map(function(o){
21    // use reduce to make objects with only the required properties
22    // and map to apply this to the filtered array as a whole
23    return props.reduce(function(newo, name){
24        newo[name] = o[name];
25        return newo;
26    }, {});
27});
28
29document.body.innerHTML = '<pre>' + JSON.stringify(result, null, 4) +
30        '</pre>';
queries leading to this page
copy array of objects from another array javascript by comparing elementscompare 2 lists get matched form 1st list in javascriptcompare two array of object and merge the propscompare two array id react nativejavascript reduce compare two object arraysjavascript match arrays by idcompare and get the match object of array from another arraycompare two array of objects and add new extra propsjs compara array object for same idusing map to match to arrays of objects by a key value using angularc 23 if two array objects idadd properties in object array from another array with matching idhow to compare two arrays if id is equal and add to new array in javascriptcomparing two arrays of objects 2c and exclude the elements who match values into new array in jsdo arrays have to match type jsmatch ids from 2 arrays in javascript asynchronous programmingcompare to array of object and add new valueif it matches javascriptjavascript compare two objects omitting one elementfind matching keys in objects within two arrays of objects javascripttwo array of objects fetch all same datahow to show two array of objects as name as separate and values are separatecompare two array of objects and copy other properties to first arraycompare two objects and return not matchedjavascript compare two arrays of json objects for matcheshow to update array with another array if keyvalue match in angular 8compare two array and create new array with matching propertiesjavascript compare two arrays of objects for non sequential matchescompare two array object using typescriptcompare array values and push seperate groupsjavascript compare two arrays of objects in vue jsjavascript compare two arrays of objects for matchescompare two arrays of objact for same valuecompare arrays and add new propertiesefficent solution two compare id of two array of objectsreturn common elements of two arrays of object javascriptmatch ids from 2 arrays in javascript asynchronous programming