JSFiddle - React, Tailwind, and code Playground
JavaScript
const rootIds = ["18828861", "15786287", "13435676"]
const filtData = [
{
year: "2022",
awards: [
{
list: [
{
rootId: "18828861",
name: "Globe",
},
{
rootId: "15786222",
name: "Golden"
},
],
},
],
},
{
year: "2021",
awards: [
{
list: [
{
rootId: "15786223",
name: "Car",
},
{
rootId: "13435676",
name: "Red",
},
],
},
{
list: [
{
rootId: "15786287",
name: "Black",
},
{
rootId: "1578622",
name: "Blue",
},
],
},
],
},
];
const res = rootIds.map((a) => a);
const findIds = filtData.map(obj => obj.awards.filter(( { list }) => list.find(o => rootIds.includes(o.rootId))));
console.log("filtData====", findIds)