In the below data array if a user is able to search with Fruits (Category) or Apple (Subcategory).
const data = [
{
"category": "Fruits",
"subCategory": [
{
"id": 1,
"val": "Apple"
},
{
"id": 2,
"val": "Banana"
}
]
},
{
"category": "Vagitable",
"subCategory": [
{
"id": 1,
"val": "Tomato"
},
{
"id": 2,
"val": "Potato"
}
]
}
]
Output: Search value "Fruits" or "Apple".
const data = [{
"category": "Fruits",
"subCategory": [
{
"id": 1,
"val": "Apple"
}
]
}]
2
Answers
You search category and subCategory by find() array manipulation method.