arrayofobjectsintersection
Can use this package to find out the common objects in between the n number of arrays and on the basis of n number of keys
Install
npm install --save arrayofobjectsintersection
Usage
const testModule = require('arrayofobjectsintersection');
let firstArray = [
{
"id":"test",
"displayName" : "Test"
}
{
"id":"demo",
"displayName" : "Demo"
}
];
let secondArray = [
{
"id" : "test",
"displayName" : "Test"
}
];
let thirdArray = [
{
"id" : "test",
"displayName" : "Test"
},
{
"id" : "user",
"displayName" : "User"
}
]
testModule.findCommonObjectsOfArrays(["id"], firstArray, secondArray, thirdArray);
//result will be
[
{
"key" : "test",
"displayName" : "Test"
}
]
When we compare all the objects in each and every array on the basis key id that is mentioned in the first parameter of findIntersectionOfArray, test id is common in all the arrays. So the result will have this object.
You can pass any number of keys in the first parameter in array format. Also you can any number of arrays from second parameter onwards