I am trying to loop and filter over a complicated data structure that consists of different arrays and objects like so:
// current tags to filter by
let filterTags = ['Folk', 'Professional']
// return the same data structure that has filtered out any events that dont
// have SecondaryTag.Title in the filterTags
let filteredEvents = allEvents.filter((el) => {
return filterTags.includes(el)
});
However, the data structure is made up of complicated arrays and objects making this very complicated.
I have tried all sorts of things which has left me smacking my head into my keyboard. Instead of posting all the ridiculous things I have tried I thought I would post what I was trying to accomplish here in hopes some kind soul will help me out.
let allEvents = [{
'2018': {
'03': {
'31': [
{
ID: 1,
Title: "My Project",
Date: "2018-02-27",
SecondaryTag: {
Title: "Professional"
}
}
],
'28': [
{
ID: 2,
Title: "My Project",
Date: "2018-02-27",
SecondaryTag: {
Title: "Business & Professional"
}
}
]
},
'04': {
'12': [
{
ID: 5,
Title: "My Project2",
Date: "2018-04-12",
SecondaryTag: {
Title: "concert"
}
}
],
'2': [
{
ID: 7,
Title: "My Project2",
Date: "2018-04-12",
SecondaryTag: {
Title: "Folk"
}
}
]
}
}
}];
// This would be the returned filtered structure given the tags
[{
'2018': {
'03': {
'31': [
{
ID: 1,
Title: "My Project",
Date: "2018-02-27",
SecondaryTag: {
Title: "Professional"
}
}
],
},
'04': {
'2': [
{
ID: 7,
Title: "My Project2",
Date: "2018-04-12",
SecondaryTag: {
Title: "Folk"
}
}
]
}
}
}]
['Folk', 'Professional'], do you wantBusiness & Professional?