Reputation: 33
I'd like to know if we can use a filter inside another filter, i have a table orders and inside we have another table services, i'd like to apply a filter where i only display the orders where the type of the service is type1 for example, itried the line of code below but it wont work:
.pipe(map(orders => orders.filter(order => order.services.map(services => services.type === 'type1'))));
orders = [{ 0: id: 1 rejected: false services: (2) [{ type: 'type1' }, { type: 'type2' }] 1: id: 2 rejected: false services: (2) [{…}, {…}] }]
Upvotes: 0
Views: 85
Reputation: 20014
If I am understanding correctly you have a list of orders
and each list of orders contains a list of services
and those services has a type
property and what you need is:
to filter only the orders of x type of service.
If the above is correct all you need to do is:
var result = listOfOrders.filter( (order) =>
order.services.some( (service) =>
service.type === myValue));
Where myValue represents the type of you service you want to filter.
Upvotes: 1