Let's say I have some code, like this:
const filter = {
address: 'India',
name: 'Aleena'
};
const users = [{
name: 'John Doe',
email: '[email protected]',
age: 25,
address: 'USA'
},
{
name: 'Aleena',
email: '[email protected]',
age: 35,
address: 'India'
},
{
name: 'Mark Smith',
email: '[email protected]',
age: 28,
address: 'England'
}
];
const filteredUsers = users.filter((item) => {
for (var key in filter) {
if (item[key] === undefined || item[key] != filter[key])
return false;
}
return true;
});
How can I dynamically update/change the filter object to allow users to choose which key:values to use in the filtering process? I know people normally use React for this kind of stuff, but I wondered if there was a "vanilla" way to do it.
dropdownviajavascriptand add some appropriateeventListeneron element and store it in variable and pass that variable forfiltercondition.