I am working with an array containing objects of this structure:
{id: 543, firstName: 'Ted', lastName: 'Foo', age: 32}
My goal is to filter out objects in the array that have the same values for both the firstName
and age
properties. The desired outcome is having multiple arrays where elements share the same values for age
AND firstName
. For example:
[{id: 543, firstName: 'Ted', lastName: 'Foo', age: 32},
{id: 123, firstName: 'Ted', lastName: 'Bar', age: 32},
{id: 432, firstName: 'Ted', lastName: 'Baz', age: 32}]
[{id: 989, firstName: 'George', lastName: 'Smith', age: 67},
{id: 876, firstName: 'George', lastName: 'Miller', age: 67},
{id: 334, firstName: 'George', lastName: 'Stone', age: 67}]
How would you approach this problem elegantly? (ES6 solutions are welcome)