let array1= [
{ "id": 100, name: "A", "details": [{"year": "2012"},{"data": "Test1"}]},
{ "id": 101, name: "B", "details": [{"year": "2013"},{"data": "Test2"}]},
{ "id": 102, name: "C", "details": [{"year": "2014"},{"data": "Test3"}]}
];
const array2= ['2012'];
Result I wanted
{ "id": 100, name: "A", "details": [{"year": "2012"}]}
I know i can filter the array with this code
array1.filter(o =>
o.details.some(p=> {
return array2.includes(p.year)
})
)
But is there a way to remove the objects as well.
.filterinto the variablearray1.