I have an array of objects with the following structure:
let optionList = [
{
images: [
{
url: "test1"
},
{
url: "test2"
}
]
},
{
images: [
{
url: "test3"
},
{
url: "test4"
}
]
},
{
images: [
{
url: "test5"
},
{
url: "test6"
}
]
}
];
I also have another array called imagesToDelete with the following values:
let imagesToDelete = ["test1", "test3", "test6"];
My goal is to remove values from the nested array based on the values in the imagesToDelete array. If done correctly, this will be the following result:
let optionList = [
{
images: [
{
url: "test2"
}
]
},
{
images: [
{
url: "test4"
}
]
},
{
images: [
{
url: "test5"
}
]
}
];
Below is my current code which did not remove any values:
optionList.filter(ol => {
let result = !ol.images.some(
image => image.url === imagesToDelete.includes(image.url)
);
return result;
});
console.log(optionList);