I needed to filter the data. My goal was to compare the data in data1
with the data in data2
and check for any error messages. Take a look at my code below. Is there a more efficient way to achieve this?
data1
[
{
"ids": "0111",
},
{
"ids": "0222",
}
{
"ids": "0333",
}
]
data2
[
{
"id": "0111",
"errorMessages": [
{
"message": ["sample error message 1"]
}
]
},
{
"id": "0333",
"errorMessages": []
}
]
Code
const filteredData = data1.filter(
(element) => element.ids === data2.find((data) => data).id
);
console.log("filtered data", filteredData);