sorry guys but i have a dummy question.. i need to iterate objects from a json response and obtain only those how meet some conditions.. the response is like this:
result = [
{
"type": "EVENT",
"id": "001",
"tags": [
{
"id": "98765",
"name": "home"
}
]
},
{
"type": "EVENT",
"id": "002",
"tags": [
{
"id": "7654",
"name": "contact"
}
]
},
{
"type": "EVENT",
"id": "003",
"tags": []
}
]
I need to use only those whose type is 'event' and name properties in tags be home.
I tried map and filter, but I do not get the desired result
const eventType = result.filter(type => type.type == 'EVENT')
const nameFilter =
eventType.map(item => item.tags)
.filter(sub => sub.length) // remove empty []
.map(subarray => subarray.map(element => element.name )
.filter(element => element == 'home'));
result:
[
['home'], // dosen t work for me, because need all the object
[],
[]
]