-2
[
    {id: 1, name: 'foo'},
    {id: 2, name: 'bar'},
    {id: 3, name: 'test'}
]

I want to get check if the data exist and use the other field. example i want to check if 'id: 1' exist in the string and the 'name:foo'

Yury Tarabanko
  • 42,049
  • 9
  • 81
  • 96
C.E James
  • 307
  • 1
  • 5
  • 19

1 Answers1

0

You can use Array.propotype.filter

var list=[
    {id: 1, name: 'foo'},
    {id: 2, name: 'bar'},
    {id: 3, name: 'test'}
]

const result = list.filter(data => data.id == 2);

console.log(result);
NullPointer
  • 6,625
  • 3
  • 24
  • 40