I have any array of objects:
array1 = [
{id: "1", policy: "abc", date: "20-05-2019" },
{id: "4", policy: "hjk", date: "12-05-2019" },
{id: "5", policy: "ikl", date: "08-05-2019" },
{id: "7", policy: "qwe", date: "20-05-2019" },
{id: "8", policy: "bdd", date: "04-05-2019" },
]
I have another large array like this:
array2 = [
{
"info" : { "insuredPolicy" : "qwe", },
"date" : { "sDate" : 20-05-2019, "eDate" : 20-06-2019 }
},
{
"info" : { "insuredPolicy" : "ikl", },
"date" : { "sDate" : 20-05-2019, "eDate" : 20-06-2019 }
},
{
"info" : { "insuredPolicy" : "bbb", },
"date" : { "sDate" : 20-05-2019, "eDate" : 20-06-2019 }
},
{
"info" : { "insuredPolicy" : "bdd", },
"date" : { "sDate" : 04-05-2019, "eDate" : 20-05-2019 }
},
];
I want to compare all policy field & date field in array1 with array2 (assume array2 is very large). then, create array of objects if policy field (array1) matches with insuredPolicy (array2) & date field in array1 matches with sDate in array2
so output will be:
array3 = [
{ policy: "qwe", date: "20-05-2019" },
{ policy: "bdd", date: "04-05-2019" },
];
In learning phase, any help will be really appreciated.
EDIT
How to compare if array2 contains sDate one day ahead? If so, then reduce sDate by 1 day and then compare. How can we achieve this?
Thanks in advance.