Filtrer array fra et andet array
HejJeg vil gerne filtrere items fra categories array ud fra kriterier i otherCategories array.
Hvis otherCategories indeholder det object hvor title matcher en title fra categories.subCategory[i].title og name matcher categories.subCategory[i].details.name så filtrer kun det object. feks "item1" fra
categories
var categories = [
{
title:"item1",
subCategory:[
{
title:"subCat1",
details:{
name:"detail1",
email:"test@test.com"
}
},
{
title:"subCat2",
details:{
name:"detail2",
email:"test@test.com"
}
}
]
},
{
title:"item2",
subCategory:[
{
title:"subCat1",
details:{
name:"detail3",
email:"test@test.com"
}
},
{
title:"subCat2",
details:{
name:"detail2",
email:"test@test.com"
}
}
]
}
]
var otherCategories = [
{
title:"subCat1",
name:"detail1"
},
{
title:"subCat2",
name:"detail1"
}
]
Det forventede resultat
categories = [
{
title:"item1",
subCategory:[
{
title:"subCat1",
details:{
name:"detail1",
email:"test@test.com"
}
}
]
}]