find intersection between two object arrays javascript
JavaScript
// Generic helper function that can be used for the three operations:
const operation = (list1, list2, isUnion = false) =>
list1.filter(
(set => a => isUnion === set.has(a.userId))(new Set(list2.map(b => b.userId)))
);
// Following functions are to be used:
const inBoth = (list1, list2) => operation(list1, list2, true),
inFirstOnly = operation,
inSecondOnly = (list1, list2) => inFirstOnly(list2, list1);
// Sample data
const list1 = [
{ userId: 1234, userName: 'XYZ' },
{ userId: 1235, userName: 'ABC' },
{ userId: 1236, userName: 'IJKL' },
{ userId: 1237, userName: 'WXYZ' },
{ userId: 1238, userName: 'LMNO' }
];
const list2 = [
{ userId: 1235, userName: 'ABC' },
{ userId: 1236, userName: 'IJKL' },
{ userId: 1252, userName: 'AAAA' }
];
console.log('inBoth:', inBoth(list1, list2));
console.log('inFirstOnly:', inFirstOnly(list1, list2));
console.log('inSecondOnly:', inSecondOnly(list1, list2));
Also in JavaScript:
- Title
- get value onChange from mat-select angular
- Category
- JavaScript
- Title
- "..." in javascript
- Category
- JavaScript
- Title
- input search picture jquery
- Category
- JavaScript
- Title
- if clicked outside of div jquery
- Category
- JavaScript
- Title
- javascript add nd st th to number
- Category
- JavaScript
- Title
- events js 292 throw er Unhandled 'error' event ^ Error getaddrinfo ENOTFOUND x86_64-apple-darwin13.4.0 at GetAddrInfoReqWrap.onlookup [as oncomplete]
- Category
- JavaScript
- Title
- custom status discord bot
- Category
- JavaScript
- Title
- how to redirect react router from the app components
- Category
- JavaScript
- Title
- c# httpclient post json stringcontent
- Category
- JavaScript
- Title
- array.filter in javascript not working in w3schools
- Category
- JavaScript
- Title
- compare string camelcase and lowercase javascript
- Category
- JavaScript
- Title
- express and node
- Category
- JavaScript
- Title
- javascript after split then trim whitespace
- Category
- JavaScript
- Title
- iterate array in javascrpt
- Category
- JavaScript
- Title
- console trace js
- Category
- JavaScript
- Title
- getelementbyid
- Category
- JavaScript
- Title
- at leastone checkbox required jquery
- Category
- JavaScript
- Title
- form taglib in jsp
- Category
- JavaScript
- Title
- convert number to k m b javascript
- Category
- JavaScript
- Title
- how to use json stringify in javascript
- Category
- JavaScript
- Title
- ajax with progress bar
- Category
- JavaScript
- Title
- get value javascript
- Category
- JavaScript
- Title
- componentwillreceiveprops hooks
- Category
- JavaScript
- Title
- angular build production
- Category
- JavaScript
- Title
- how to freeze js object
- Category
- JavaScript
- Title
- create array with specific size javascript
- Category
- JavaScript
- Title
- add select option jquery
- Category
- JavaScript
- Title
- get screen width javascript
- Category
- JavaScript
- Title
- how to split an array in javascript
- Category
- JavaScript
- Title
- anagram javascript example
- Category
- JavaScript
- Title
- how to get element from arraylist react
- Category
- JavaScript
- Title
- autocomplete list angular 8 material
- Category
- JavaScript
- Title
- how to get the last element in javascript
- Category
- JavaScript
- Title
- add all elements in array javascript
- Category
- JavaScript
- Title
- event handler attachment jquery
- Category
- JavaScript
- Title
- Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project electronicbookshop: Compilation failure
- Category
- JavaScript
- Title
- how to use hooks react
- Category
- JavaScript
- Title
- auto refresh page javascript
- Category
- JavaScript
- Title
- discord.js multiple embeds
- Category
- JavaScript
- Title
- include javascript jquery file in html
- Category
- JavaScript
- Title
- expo open app settings
- Category
- JavaScript
- Title
- code to launch browser using javascript
- Category
- JavaScript
- Title
- how run dockerfile
- Category
- JavaScript
- Title
- find the last occurrence of a character in a string javascript
- Category
- JavaScript
- Title
- firestore set a document
- Category
- JavaScript
- Title
- create element javascript with class
- Category
- JavaScript
- Title
- import json file javascript
- Category
- JavaScript
- Title
- how to auto refresh page in javascript
- Category
- JavaScript
- Title
- add month date now javascript
- Category
- JavaScript
- Title
- dataset js
- Category
- JavaScript
- Title
- javascript add text to textarea overwrite
- Category
- JavaScript
- Title
- how to loop over dom objects javascript
- Category
- JavaScript
- Title
- compare two arrays javascript
- Category
- JavaScript
- Title
- how to find remainder in javascript
- Category
- JavaScript
- Title
- fsharp newtonsoft json deserialize
- Category
- JavaScript
- Title
- how to add changes every time you route navigate to page in angular
- Category
- JavaScript
- Title
- how to get element by title js
- Category
- JavaScript
- Title
- html external javascript
- Category
- JavaScript
- Title
- how to update all node libraries
- Category
- JavaScript
- Title
- how to split two digit number in javascript
- Category
- JavaScript
- Title
- background-image url not working
- Category
- JavaScript
- Title
- area of a circle
- Category
- JavaScript
- Title
- get url of page in background script
- Category
- JavaScript
- Title
- how to use jQuery hide and show to display multiple images
- Category
- JavaScript
- Title
- angular lifecycle hooks
- Category
- JavaScript
- Title
- how to find out what a string ends with in javascript
- Category
- JavaScript
- Title
- angular right click on link
- Category
- JavaScript
- Title
- convert jquery to javascript
- Category
- JavaScript
- Title
- get the state of a checkbox
- Category
- JavaScript
- Title
- discord js channel count
- Category
- JavaScript
- Title
- how to make a text editor in html
- Category
- JavaScript
- Title
- how to make a proxy server node.js
- Category
- JavaScript
- Title
- how to filter object in javascript
- Category
- JavaScript
- Title
- document addeventlistener click
- Category
- JavaScript
- Title
- array sort by key javascript
- Category
- JavaScript
- Title
- how to program an array in js
- Category
- JavaScript
- Title
- how to animate array oy react elements
- Category
- JavaScript
- Title
- add char in specific index stirng javascript
- Category
- JavaScript
- Title
- delete from array based on value javascript
- Category
- JavaScript
- Title
- How to check whether a checkbox is checked in jQuery?
- Category
- JavaScript
- Title
- ad data to js object
- Category
- JavaScript
- Title
- check if string is datestring javascript
- Category
- JavaScript
- Title
- delete previous line node
- Category
- JavaScript
- Title
- contact form7 404 wp-json feedback
- Category
- JavaScript
- Title
- deno
- Category
- JavaScript
- Title
- hexstring to rgb array js
- Category
- JavaScript
- Title
- 2 taps is required to close keyboad in react native
- Category
- JavaScript
- Title
- cannot read property 'props' of undefined react redux functional component
- Category
- JavaScript
- Title
- how to make a show password button
- Category
- JavaScript
- Title
- how to load localt ext file in js
- Category
- JavaScript
- Title
- angular stoppropagatio
- Category
- JavaScript
- Title
- FUNCION EN OBJETO JAVASCRIPT
- Category
- JavaScript
- Title
- javascript change element id
- Category
- JavaScript
- Title
- empty a select input using js
- Category
- JavaScript
- Title
- how to take input in javascript in coding
- Category
- JavaScript
- Title
- clone an object javascript
- Category
- JavaScript
- Title
- how to print a array js
- Category
- JavaScript
- Title
- divide intagers javascript
- Category
- JavaScript
- Title
- array data structure javascipt interview questions
- Category
- JavaScript
- Title
- backbone js event listener
- Category
- JavaScript