Check if array of objects contains value

Published on August 23rd, 2019

javascript icon

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
}