I've an array which contains the objects including various key and values. I'm going to pick out the certain values from the Array and check if the specific value is included or not in the Array.
function groupByName (contract) {
const { age } = contract;
const groups = [
{name: 'John', age: 30},
{name: 'Jack', age: 33},
{name: 'Tom', age: 40}
...
];
...
}
In order to compare the age
in groups
array, right now I have to use loop functions and then check one by one.
Like
groups.forEach(g => {
if (g.age === age) {
...
} else {
...
}
});
But I don't like this approach and think there are simple and effective way. Please help me!