How I have some nested array of object, And I tried to get matched items with some value which stored in the nested object in this object and there is have nested array also.
Eg:
my data:
const items = [
{
name: "A",
data: {
title: "B",
subData: {
val: "AA",
anotherData: {
subC: [
{
name: "Data Item",
fruits: ["Apple"]
},
{
name: "Data Item 2",
fruits: ["Orange"]
}
]
}
}
}
},
{
name: "A",
data: {
title: "B",
subData: {
val: "AA",
anotherData: {
subC: [
{
name: "Data Item",
fruits: ["Apple"]
},
{
name: "Data Item 2",
fruits: ["Orange"]
}
]
}
}
}
}
]
Here is my data I have a value of fruit eg: "Apple", and I need to get all items which contain Apple fruits array
how to do that with the es6 map or filter function?.
I tried this solution but getting undefined
const v = items.map((item) => {
return item;
}).map((a) => {
return a.data.subData.anotherData
}).map((b) => {
console.log("b", b)
return b
}).map((x) => {
return x
}).filter((o) => {
return o.fruits.contains["Apple"]
});