I have this items array and a filterParams array.
const items = [
{
count: 1,
operation: 'Change Status',
area: 'dish_names',
days: '2019-07-17'
},
{
count: 14,
operation: 'Create',
area: 'dishes',
days: '2019-07-17'
},
{
count: 23,
operation: 'Create',
area: 'dish_names',
days: '2019-07-17'
},
{ count: 1, operation: 'Delete', area: 'dishes', days: '2019-07-17' },
{
count: 2,
operation: 'Update',
area: 'dish_names',
days: '2019-07-17'
}
]
const filterParams = [
'restaurant_menu_masters=Update',
'dish_categories=Update',
'dishes=Create'
]
What I want is to filter the items array using filterParams.
If filterParams array only has one element, I would easily do it like this
const data = items.filter(Element=> {
let params = filterParams[0].split("=");
return Element.area === params[0] && Element.operation === params[1]
})
Basically What I did was, take the params string and split it by "=" and then check first part of the param equals to area and the second to operation. My problem is it has more than one filter parameters in that array and I want to check all of that.
How do I achieve this using JS?
Any help!
Thanks in advance =)