I'm trying to determine the best approach to the following.
I have two arrays, as per the below:
const a = [
{
Employee: "00001",
Seq: "01",
ReportDate: "2021-03-10T00:00:00.000",
ReportName: "test report",
},
{
Employee: "00002",
Seq: "01",
ReportDate: "2020-03-10T00:00:00.000",
ReportName: "test report 2",
},
];
const b = [
{
Employee: "00001",
EmplName: "William Apple",
ReportDate: "2021-03-10T00:00:00.000",
ReportName: "test report",
Posted: "Y",
Seq: "01",
},
{
Employee: "00003",
EmplName: "John Smith",
ReportDate: "2021-03-10T00:00:00.000",
ReportName: "test report 3",
Posted: "Y",
Seq: "01",
},
];
I want to filter out anything in array 'b', that does not contain ALL 4 of the exact values in in one of the objects within Array 'a'.
So, as per the examples above, I would be left with:
// from array 'b'
const c = [
{
Employee: "00001",
EmplName: "William Apple",
ReportDate: "2021-03-10T00:00:00.000",
ReportName: "test report",
Posted: "Y",
Seq: "01",
}
];
I have looked at various ways to do this. I cannot just check to see if the objects are equal, as array 'a' will only contain 4 value/keys, and array 'b' will have many more / a dynamic amount.
Would using the Filter method through a loop and multiple IF statements be the best approach?