Skip to content

Check value exists in array

check is object value is exists in array

Muhamad Ristiyanto

Created by / Muhamad Ristiyanto

JAVASCRIPT
// check value of object is exists in array?

let arr = [
  { id: 1, name: 'umam' },
  { id: 2, name: 'faisal' },
  { id: 3, name: 'ikbal' }
]
const query = 'ikbal'

// check
arr.some(v => v.name == query) // true

// or use filter if you want get the data too

arr.filter(x => x.name == query) [ { id: 3, name: 'ikbal' } ]