I have 2 arrays one is “searchEachIndex” and another one is “data”.
Based on “searchEachIndex” array i want to filter the “data” array. i.e,
Here in searchEachIndex array i have 123 value that matches with data array’s employeId.
should push the object into res array here { id: 2, employeId: 123 }, { id: 3, employeId: 123 }, If both values matches.
otherwise push the mismatching searchEachIndex values here 1234, 12 into another array i.e, noData array.
let searchEachIndex = [123, 1234, 12]
let data = [
{
id: 1,
employeId: 121
},
{
id: 2,
employeId: 123
},
{
id: 3,
employeId: 123
}
];
let res=[];
let noData = [];
searchEachIndex.forEach(val => {
data.map(item => {
if(item.employeId === val) {
res.push(item)
}
})
})
console.log('Both emp id and searchEachIndex value matched array', res);
consolelog('Ids not found array', noData);