I have an array like that:
const array = [
{
id: 1,
list: [
{
name: "abc",
quantity: 46,
},
{
name: "abc cba",
quantity: 8,
},
]
}
{
id: 2,
list: [
{
name: "def",
quantity: 895,
},
{
name: "abc ebn",
quantity: 8,
},
]
}
]
What would be the best way to filter this array, if I want to check if the array contains: name: "abc" and filter only the objects containing this?
i've tried to use map.() inside filter(), but i don't know if it's a proper way to do this. My code is something like this:
let filteredArray = array.filter(el => {
let filteredName;
el.list.map (name => {
if (elt.name.includes("abc"){
filteredName = name
}
}
return filteredName;
})