Consider the following scenario: an array is provided as input containing various objects with nested elements. The goal is to filter this array in JavaScript and obtain a new array consisting only of objects where the key "navigation" has a value of true.
[
{
"name": "home page",
"title": "Find Jobs in Technology",
"url": "https://www.url1.com/",
"elements": [
{
"category": "navigation",
"buttons": [
{
"title": "Tech Careers",
"type": "DropDown",
"options": [
{
"title": "Job Search",
"type": "Button",
"navigation": true
},
{
"title": "Career Events",
"type": "Button",
"navigation": false
}
]
},
{
"title": "Insights",
"type": "Link",
"navigation": true
}
]
}
]
},
{
"name": "tech careers",
"title": "careers",
"url": "https://www.url1.com/careers",
"elements": [
{
"category": "navigation",
"buttons": [
{
"title": "Login",
"type": "Link",
"navigation": true
}
]
}
]
}
]
The expected result after filtering should be a new array that includes only objects where the "navigation" key is true. See the example below:
[
{
"title": "Job Search",
"type": "Button",
"navigation": true
},
{
"title": "Insights",
"type": "Link",
"navigation": true
},
{
"title": "Login",
"type": "Link",
"navigation": true
}
]
Your assistance in achieving this outcome would be greatly appreciated. Please note that previous attempts using array.filter have not been successful due to limitations when dealing with nested structures.