const data = {
apple: {
type: 'fruit',
image: './fruit/apple.jpg'
},
orange: {
type: 'fruit',
image: './fruit/orange.jpg'
}
carrrot: {
type: 'vegetable',
image: './vegetable/carrot.jpg'
}
}
I am trying to build a search function to loop through an object to return the items I need.
for example, if I want all the fruit, the image of apple and orange will be rendered.
I need something like this:
list = []
for item in data:
if item.type == 'fruit':
list.append(item)
return list
What is the proper code in React Native? Thanks in advance.