In a React project, I'm calling data from JSON data as:
In short JSON data is as:
const listData = [
{
"_id":"abscdf456",
"bucket": {code: "videos"}
"contents": [
{}, {}, {}, {}
]
},
{
"_id":"absusi789",
"bucket": {code: "videos"}
"contents": [
{}, {}, {}, {}, {}, {}
]
},
{
"_id":"abssth7890",
"bucket": {code: "photos"}
"contents": [
{}, {}, {}, {},{}, {},{}, {}, {}
]
},
{
"_id":"yuiaf456",
"bucket": {code: "videos"}
"contents": [
{}, {}, {}
]
}
]
I have tried in the following way
listData.map((data) => (
<div>
{
data.bucket.code == "videos" ?
({/* Map only videos contents object */}) : ({/* Map only photos contents object */})
}
</div>
))
Another trial I did is const videoData = listData.filter(data => data.bucket.code === "videos")
but, no use as It got repeated many times
So basically My intention is to map the 'contents object' of each bucket non-repeated. What could be the best possible solution?