Check if array of objects contains

Last update in 8/2019

This is one of those simple problems I encounter every few days and find myself searching through visited stack overflow questions, so here is solution, once and for all.

Let's say you have some object data in array similar to this.

const users = [
{
name: 'John',
email: '[email protected]',
},
{
name: 'Bartol',
email: '[email protected]',
},
]

And you want do something only for user with specific name.

if (users.some(e => e.name === 'Bartol')) {
// do something
}

Resources #