I need to filter this array so it is only left with the correct category codes
const yearLayers=
[
{
"year": 2016,
"eventNodes": [
{"header": "Pearls of Wisdom", "categoryCode": 3,}
]
},
{
"year": 2017,
"eventNodes":[
{"header": "VENuS Satellite", "categoryCode": 2},
{"header": "Hope for millions", "categoryCode": 1}
]
},
{
"year": 2012,
"eventNodes": [
{"header": "green electricity Pioneer", "categoryCode": 1}
{"header": "This is a header", "categoryCode": 3,}
{"header": "more titles here", "categoryCode": 1,}
]
}
]
This is a snippet of what the array looks like. I need to filter out the objects with the category code that does not === 1. So I left with an array with only categoryCode: 1.
const yearLayers=
[
{
"year": 2016,
"eventNodes": []
},
{
"year": 2017,
"eventNodes":[
{"header": "Hope for millions", "categoryCode": 1}
]
},
{
"year": 2012,
"eventNodes": [
{"header": "green electricity Pioneer", "categoryCode": 1}
{"header": "more titles here", "categoryCode": 1,}
]
}
]
I have tried to use array methods, but I cannot seem to reach inside the nested array and the nested objects. I think I am missing something
const filteredArr = yearLayers
.map(layer => layer.eventNodes)
.map(node => node.categoryCode)
.filter(node => node.categoryCode !== 1)