I am working with an array of objects, each containing properties like category name, categoryId, and a subcategory list which is an array. I need to filter the data based on both the name and values in the subcategory list. Here is a sample of my array:
var statesWithFlags = [
{ subCategoriesList: ['Badges and dentures', 'Cerezens', 'Dental implants'], categoryId: 1, categoryName: "Dental" },
{ subCategoriesList: ['Badges and dentures44', 'Dental implants'], categoryId: 2, categoryName: "Dermatology" },
{ subCategoriesList: ['Badges and dentures', 'Cerezens', 'Dental implants222'], categoryId: 3, categoryName: "Eye" },
{ subCategoriesList: ['Badges and dentures', 'Cerezens', 'Dental implants', 'Cerezens'], categoryId: 4, categoryName: "Ayurvedic" }
]
Currently, I have a filtering mechanism that only works for the categoryName property. I would like to modify this to work for the subcategory list as well.
this.statesWithFlags.filter(v => v.categoryName.toLowerCase().indexOf(term.toLowerCase()) > -1)).slice(0, 10))