вы можете использовать Array#filter
для массива1 с Array#some
для массива2 для фильтрации необходимых элементов.
const 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" },]
const 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' }},];
let out = array1.filter(({policy, date}) => array2.some(e => e.info.insuredPolicy === policy && e.date.sDate === date));
console.log(out)
РЕДАКТИРОВАТЬ: В соответствии с новым требованием
вы можете написать метод для получения предыдущей строки даты следующим образом
const 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" },]
const array2 = [{"info" : { "insuredPolicy" : "qwe", },"date" : { "sDate" : '21-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' }},];
function yesterday(str) {
return str.replace(/\d{2}/, (p1) => (p1 - 1).toString().padStart(2, 0))
}
let out = array1.filter(({policy, date}) => array2.some(e => e.info.insuredPolicy === policy && yesterday(e.date.sDate) === date));
console.log(out)