My JSON data looks like this:
{
"data": [{
"id": "1",
"blogTitle": "How to plant a tree?",
"categories": [{
"CategoryID": "10",
"CategoryTitle": "Apple Tree"
}, {
"CategoryID": "11",
"CategoryTitle": "Mango Tree"
}, {
"CategoryID": "42",
"CategoryTitle": "Banana Tree"
}]
},
{
"id": "2",
"blogTitle": "How to make Juice?",
"categories": [{
"CategoryID": "71",
"CategoryTitle": "Apple Juice"
}, {
"CategoryID": "72",
"CategoryTitle": "Mango Juice"
}, {
"CategoryID": "73",
"CategoryTitle": "Banana Juice"
}]
}
]
}
What I want is to get the value of id by passing the value of CategoryID
For example: if I send 10 then I should get 1 in return because "CategoryID": "10" is in the same block with "id": "1"
Each CategoryID is unique resulting in a unique value of id
What did I do?
- Closest I came up with was using the
array.filter()but I am able to filteridvalue give the value ofidbut how do I get the value ofid, givenCategoryID
Could someone please kindly help me?