let users = [
{
name: 'user 1',
services: [
{
title: 'service 1',
categories: ['category 1', 'category 2']
},
{
title: 'service 2',
categories: ['category 3', 'category 4']
},
{
title: 'service 3',
categories: ['category 5', 'category 6']
}
]
},
{
name: 'user 2',
services: [
{
title: 'service 4',
categories: ['category 7', 'category 8']
},
{
title: 'service 5',
categories: ['category 9', 'category 10']
},
{
title: 'service 6',
categories: ['category 11', 'category 12']
}
]
}
];
let filterBy = ['category 5', 'category 6']; // отфильтровать на наличие данных категорий в объекте.
users.filter(u => u.services.some(s => filterBy.every(f => s.categories.includes(f))))
users.filter(u => filterBy.every(f => u.services.some(s => s.categories.includes(f))))
users.filter(u => filterBy.some(f => u.services.some(s => s.categories.includes(f))))
let users = [
{
name: 'user 1',
services: [
{
title: 'service 1',
categories: ['category 1', 'category 2']
},
{
title: 'service 2',
categories: ['category 3', 'category 4']
},
{
title: 'service 3',
categories: ['category 5', 'category 6', 'category 11']
}
]
},
{
name: 'user 2',
services: [
{
title: 'service 4',
categories: ['category 7', 'category 8']
},
{
title: 'service 5',
categories: ['category 9', 'category 10']
},
{
title: 'service 6',
categories: ['category 11', 'category 12']
}
]
}
];
let filterBy = ['category 5', 'category 6', 'category 11'];
let usersUPD = [];
for (let item of users) {
for (let item2 of item.services) {
if (item2.categories.some(i => filterBy.includes(i))) {
usersUPD.push(item)
}
}
}
console.log(usersUPD)