How to filter a json result using react native?

The question is the same of the title: How to filter a json result using react native?

I have a simple json result:

[{"id":"1","title":"Outlet_Usou","category":"Rouparia","latitude":"-8.616075000000000","longitude":"-35.95577800000000"},
 {"id":"2","title":"Studio F7","category":"Academia","latitude":"-8.609749000000000","longitude":"-35.94622500000000"},
 {"id":"3","title":"Pizzaria Popular","category":"Pizzaria","latitude":"-8.599646000000000","longitude":"-35.95055900000000"}]

I receive and list this json using map function.

How do can I filter for title or category fields?

1 answer

  • answered 2018-02-13 00:41 Joe - New Nine

    Let's say your array is assigned to a variable data:

    const pizzerie = data.filter( (item) => {
      return item.category === 'Pizzaria'
    })
    

    This would give you an array (pizzerie) of data objects that match that category. You can edit to check titles...whatever.