I am trying to filter a sub array of a parent array and my results are coming back empty. I am trying to find matches to the color_family.
My array looks like:
const arr =[
{
"id": 123,
"acf": {
"product_colors": [
{
"color_family": "grey"
},
{
"color_family": "taupe"
}
]
}
},
{
"id": 456,
"acf": {
"product_colors": [
{
"color_family": "red"
},
{
"color_family": "taupe"
}
]
}
}
]
What I am filtering on is
const findColors = ["grey", "taupe"]
What I have tried with no luck is
const res = arr.filter(
x => x.acf.product_colors.find(
color_family => findColors.includes(color_family)
)
)
This is returning no results when it should return 2 results. Can someone point me in the right direction?