How can I filter my array of objects by property name and value?
For example, I have to filter objects if their property aa.town
is Edinburgh
I need to filter using whatever object literal is passed as a parameter - I do not want to hardcode the value.
What I have tried so far is
export function objectFilter(people, 'aa.town', 'Edinburgh'); {
return objects.filter(item => item[keysString] == searchString);
}
Here is a people array:
export const people = [
{
a: 'Jim',
b: 'male',
c: '1971',
aa: {
town: 'London',
},
},
{
a: 'Bob',
b: 'male',
c: '1971',
aa: {
town: 'Edinburgh',
},
},