Italo Rodrigo
Italo Rodrigo

Reputation: 1785

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?

Upvotes: 0

Views: 630

Answers (1)

I'm Joe Too
I'm Joe Too

Reputation: 5840

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.

Upvotes: 3

Related Questions