-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
  • 44,270
  • 9
  • 84
  • 98
C.E James
  • 315
  • 1
  • 5
  • 22

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
  • 7,094
  • 5
  • 27
  • 41