I have an array of objects:
And I want to remove the object, that has a specific date (2020-09-24 in this example) in the excluded_dates Array to output the new Array like this:
outcome = [
{
title: '"test1"',
excluded_dates: false,
},
{
title: '"test2"',
excluded_dates: [
{ excluded_date: "2020-09-12" },
{
excluded_date: "2020-09-17",
},
],
}
];
For this, I was thinking of using double filtering. I also tried some(), but that is for Arrays, not an Array of Objects.
const data = [
{
title: '"test1"',
excluded_dates: false,
},
{
title: '"test2"',
excluded_dates: [
{ excluded_date: "2020-09-12" },
{
excluded_date: "2020-09-17",
},
],
},
{
title: '"test3"',
excluded_dates: [
{
excluded_date: "2020-09-16",
},
{
excluded_date: "2020-09-24",
},
],
},
];
const outcome = data.filter(function (event) {
if (event.excluded_dates) {
return event.excluded_dates.filter(
(date) => date.excluded_date === "2020-09-24"
);
}
});
console.log(outcome);
This ofcourse doesn't work as expected. What am I'm missing here?