I am looking to filter my array of accordion items based on the value of the question matching the input I provide. I have tried using the filter method for this.
this.accordionItems = [
{
"topic":"polizze",
"question":"Le mie polizze sono attive?",
"answer":"Lorem ipsum dolor sit amet, consectetur adipiscing… qui officia deserunt mollit anim id est laborum."
},
{
"topic":"polizze",
"question":"Come si cambia il beneficiario?",
"answer":"Lorem ipsum dolor sit amet, consectetur adipiscing… qui officia deserunt mollit anim id est laborum."
},
{
"topic":"sinistri",
"question":"Come annullo un appuntamento?",
"answer":"Lorem ipsum dolor sit amet, consectetur adipiscing… qui officia deserunt mollit anim id est laborum."
}
]
this.input = 'polizze';
if (this.accordionItems) {
this.accordionItems = this.accordionItems.filter(request =>
request.question.toLowerCase() === this.input.toLowerCase());
}