I have the following structure:
const structure = [
{
"item_type": "questionnaire",
"questionnaire_type": "profile",
"questions": [
{
"id": "a123c388-5e65-e711-8358-000c29a887ad",
"type": "one_answer",
"title": "Participant segment"
}
]
},
{
"item_type": "questionnaire",
"questionnaire_type": "system_information",
"questions": [
{
"id": "0624c388-5e65-e711-8358-000c29a887ad",
"type": "one_answer",
"title": "Operating System"
},
{
"id": "1e24c388-5e65-e711-8358-000c29a887ad",
"type": "one_answer",
"title": "Browsers"
},
{
"id": "5224c388-5e65-e711-8358-000c29a887ad",
"type": "one_answer",
"title": "Screen Resolution"
},
{
"id": "8524c388-5e65-e711-8358-000c29a887ad",
"type": "one_answer",
"title": "Browser Resolution"
}
]
},
{
"item_type": "questionnaire",
"questionnaire_type": "final_questionnaire",
"questions": [
{
"id": "0326c388-5e65-e711-8358-000c29a887ad",
"type": "one_answer",
"title": "af"
}
]
}
]
and I trying to filter the items of the structure with the following code:
const term = RegExp('Browsers')
structure.filter(item =>
item.questions.find(question => term.test(question.title)))
and I getting:
{
item_type: "questionnaire",
questionnaire_type: "system_information",
questions:[
{id: "0624c388-5e65-e711-8358-000c29a887ad", type: "one_answer", title: "Operating System"},
{id: "1e24c388-5e65-e711-8358-000c29a887ad", type: "one_answer", title: "Browsers"},
{id: "5224c388-5e65-e711-8358-000c29a887ad", type: "one_answer", title: "Screen Resolution"}3: {id: "8524c388-5e65-e711-8358-000c29a887ad", type: "one_answer", title: "Browser Resolution"}
}
but I need:
{
item_type: "questionnaire",
questionnaire_type: "system_information",
questions:[
{id: "1e24c388-5e65-e711-8358-000c29a887ad", type: "one_answer", title: "Browsers"}
}
how can I get only what I need