I am dealing with a multi-dimensional array where each object shares the same keys.
export const MENUS = [
{
"type": "main",
"submenu": [],
"path": "/a"
},
{
"type": "main",
"submenu": [
{
"type": "submenu",
"submenu": [
{
"type": "submenu",
"submenu": [],
"path": "/b/4"
},
],
"path": null
},
{
"type": "submenu",
"submenu": [],
"path": "/b/1"
}
],
"path": null
},
{
"type": "main",
"submenu": [],
"path": "/c"
}
]
I need to retrieve the parent object based on a specific key and value pair (e.g. path: '/b/1') within the array.
The expected result when using { path: '/b/1' } should be as follows:
{
"type": "main",
"submenu": [
{
"type": "submenu",
"submenu": [
{
"type": "submenu",
"submenu": [],
"path": "/b/4"
},
],
"path": null
},
{
"type": "submenu",
"submenu": [],
"path": "/b/1"
}
],
"path": null
},
If I use { path: '/c' }, then the root array will be returned (equivalent to MENU). If you have a solution to this problem, please share it with me. Thank you.