const arr = [
{label : 'lbl1', text: 'txt1'},
{label : 'lbl2', text: 'txt2'},
{label : 'lbl3', text: 'txt3'},
{label : 'lbl4', text: 'txt4'},
// much more items
];
const filterBy = [
{label: 'lbl1',text: 'txt1'},
{label : 'lbl4', text: 'txt4'}
//may have 0 or more items
];
I want to dynamically filter arr by filterBy. filterBy is coming from the UI... here its just a representation of what the user can pass...
in a static way I would do:
arr.filter(x => (x.text == filterBy[0].text && x.label == filterBy[0].label) ||
. (x.text == filterBy[1].text && x.label == filterBy[1].label)
);
Is it possible to chain dynamic criterions in JS? Thanks
filterBycan also have not 2, but many items in it?filterByis already a filtered version ofarrfilterByis something the use pass to, to it is totally dynamicfilterByandarrshould be filtered by it. Is that right?